Facebook php sdk - post to a wall with prompt - php

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/

Related

Posting to multiple facebook friends wall (in my case 20)

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

How to auto publish on application's wall using PHP

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);

Publish on user's wall using application's name

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..!!!

how to post on a facebook event wall?

Im new at facebook app development and I am trying to make an automatic post on an event wall. I have read that include the id to post on a specific wall. I have tried that but it doesn't work.
I thought that maybe it would work with "to" (a specific targeted wall), but I don't know it's syntax...
can anyone help? or at least give an example of a post syntax with a "to" property included... plssss...
$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'))
);
$uid = ""; //friend id OR "me"
$result = $facebook->api('/'.$uid.'/feed/','post',$attachment);
http://developers.facebook.com/docs/reference/api/post/
NOTE: you should have the user publish_stream extended permission and you should have the SDK Lib loaded.
$attachment = array(
'message' => 'this is my message'
);
$eid = ""; //event id
$result = $facebook->api('/'.$eid.'/feed/','post',$attachment);
http://developers.facebook.com/docs/reference/api/event/ <-- event object documentation
or
https://api.facebook.com/method/stream.publish?message=<your_message>&target_id=<event_id>&access_token=<your_token>

Posting on friend's wall

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

Categories