I'm using Facebook GRAPH API to publish on user's wall.
It works fine, but I'm encountering a little problem:
My publication appears on the user's wall with the user's name, as if he published himself
I want to publish on his wall but with my application's name
How can I do this ?
First you need user post stream permission. After you get user credential, then you can try send $_POST with structure like these
$stream_data = array(
'access_token' => $user_access_token,
'caption' => 'From Your App',
'description' => 'Your App description',
'link' => 'http://yourapp.com',
'picture' => 'http://yourapp.com/assets/img/someicon.png',
'name' => $user_sess_name.' just started uses Your App name.',
);
to https://graph.facebook.com/1234/feed (1234 is a user id) to create a feed stream.
There is no way to post on a user's wall and have it attributed to the app itself, only users may write on each other's walls, there's no way for an app or Page to write on a Profile's wall.
toopay's answer is a good example of posting to a user's wall from an app, but that post would be attributed to the user whose access token you use
I don't think so you can post on user's wall with the app name, You can use the below code to post on user wall and it will say on the Bottom VIA app name
$fb = new Facebook(array(
'appId' => '2420527xxxxxxx',
'secret' => 'a6b14d618xxxxxxxxxxxxxxxxxxx'
));
try {
$attachment = array(
'message' => '',
'access_token' => $fb->getAccessToken(),
'name' => 'Attachment Name',
'caption' => 'Attachment Caption',
'link' => 'http://www.xxxxxxx.com/app/',
'description' => 'Description .....',
'picture' => 'http://www.xxxxxxx.com/logo.xxx',
'actions' => array(array('name' => 'Action Text','link' =>'http://www.xxx.com/app/'))
);
$result = $fb->api('/'.$fb->getAppId().'/feed/', 'post', $attachment);
echo $result;
}catch (FacebookApiException $e) {
echo $e->getMessage()."\n";
}
Try it..!!!
Related
I'm doing a facebook app and it was working good till yesterday. I did was let user's choose 20 of their friends and wrote a simple script to post to their wall from a loop like this:
foreach($selectedids as $selectedid) {
$invitation = new Invitations();
$invitation->circle_id = $circle->id;
$invitation->status = 0;
$invitation->follower_id = $selectedid;
if ($invitation->create()) {
$id = $invitation->id;
// Now Send the Invitations on Facebook
$facebook->api($selectedid.'/feed', 'post', array(
'picture' => '',
'message' => $name."something",
'name' => $config['app_title'],
'link' => $config['redirect_uri']."?invitation=".$id,
'caption' => '',
'description' => '',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
));
}
}
Till yesterday everything was fine but when now multiple user's use this at once the script would stop after a post to about 7-8 friend and give an error that it couldn't complete task. Is there a better way to post to multiple peoples in facebook? What shall I do, would make this perform better? Any suggestions would be much appreciated.
Checking log an exception: 'error 201 user not visible' was found.
Thanks in advance.
How about puting the api call into a variable and checking the variable.?
$result = $facebook->api($selectedid.'/feed', 'post', array(
'picture' => '',
'message' => $name."something",
'name' => $config['app_title'],
'link' => $config['redirect_uri']."?invitation=".$id,
'caption' => '',
'description' => '',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
));
Because if it is successfull, it will send you back the id of the post.
The error was due the user not being able to post to his friends wall which I solved by doing a check before posting by running a fql to check 'can_post' to user's friends wall. Solution can be viewed at.
Check if a facebook user can post in his friends wall or not
I have requirement that whatever I store on server database (like adding new question), it should auto publish to application's wall so that users who likes application can see regular updates.
How is it possible using PHP?
Any answer would be appreciated.
Thanks in advance.
You have to set a listener that will read the new changes on db or from the interface where u are setting the data for the database call the fb api and post it inmediatly... in that case would be something like this.
$autpost = array('message' => ' message',
'name' => 'This is my demo',
'caption' => "Caption ",
'link' => 'http://facebook.com',
'description' => 'description',
'picture' => 'http://somesite.picture.jpg',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$result = $facebook->api('/fanpage id/feed/', 'post', $wall_post);
T'm writing a Facebook canvas app, and I'm trying to post to the user's wall. this the code I'm using:
if ($user) {
$attachment = array('message' => 'This is message',
'name' => 'Name of the message',
'caption' => 'Caption of link',
'link' => 'http://www.example.com/about',
'description' => 'Great site!',
'picture' => 'http://lorempixum.com/100/100/',
'actions' => array(array('name' => 'Do Something!',
'link' => 'http://www.example.com'))
);
$result = $facebook->api('/me/feed/',
'post',
$attachment);
}
So I tested with 2 facebook accounts, and it posts to the wall but without the facebook dialog i'm always seeing. I would like the user to be warned that I'm gonna post on the wall, and allow him to cancel it.
How do I do that?
You need to use the JavaScript SDK, essentially the dialogs bit: http://developers.facebook.com/docs/reference/dialogs/feed/
I am desperately looking for image attachment php api feeds for my facebook app.
Basically what I am trying to do is send an image attachment, along with an automatic "post to friends wall" action.
The idea behind it is that a user sends a "virtual burger" to their friends wall, with a message offering them a discount.
This is a snippet of the code that successfully sends the message, but I can't get the attachment to work.
if($_REQUEST['friend_1']!='' && $_REQUEST['friend_1']!="Start typing a friend's name") {
try {
$fql1 = "select name from user where uid=" . $_REQUEST['friend_1'];
$param1 = array(
'method' => 'fql.query',
'query' => $fql1,
'callback' => ''
);
$fqlResult1 = $facebook->api($param1);
$friend_1_name = $fqlResult1[0]['name'];
$statusUpdate = $facebook->api('/'.$_REQUEST['friend_1'].'/feed', 'post', array('link' => $fanpageURL, 'name' => 'Have a virtual Unity Burger.', 'description' => " ".$user_name." just sent you a virtual Unity Burger. If you would rather have the real thing then come add your name on the Unity list and we will give you a 20% discount on your next visit and an exclusive Unity keyring.", 'properties' => '', 'cb' => ''));
} catch (FacebookApiException $e) {
//echo "Notification not send to user ".$fqlResult1[0]['name']."<br>";
I think there are two ways to attach an image to a wall post.
The first one is to define the meta og:image in the target page and post the link to the friends wall. Facebook will query the target and grab the Open Graph info displaying it in the wall. You can test this with the Facebook Debugger.
The meta property should look like this:
<meta property="og:image" content="http://url.to/image" />
You can also define other Open Graph properties like title, description, etc.
The second way to attach the image to the post is to include the picture parameter in the Graph API call. In your code you only define some parameters (link, name, description...) but you can also send picture, caption, message...
So your API call could be like this:
$params = array( 'access_token' => '',
'message' => '',
'link' => '',
'picture' => '',
'name' => '',
'caption' => '',
'description' => ''
);
$wallPost = $facebook->api('/'.$to.'/feed', 'post', $params);
How do I post to friend's wall using PHP Graph API? I got some javascript solutions. But I need PHP ones. Thank you.
Check the documentation here http://developers.facebook.com/docs/reference/api/post/.
Try $facebook->api('/Friend_ID/feed','post',array('message'=$message));. Refer to the documention for more parameters.
it requires few things
Create a Facebook Application: FB Documentation
Request extended permissions to access a user's photos and their friend's photos Facebook Auth / Permissions
FQL + JSDK to request the data JSDK Doc
$attachment = array('message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://mylink.com',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$result = $facebook->api('/me/feed/',
'post',
$attachment);
good luck