Posting on friend's wall - php

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

Related

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

Facebook php sdk - post to a wall with prompt

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/

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>

How can I post to the wall of a Facebook Fan Page using PHP and Open Graph API

Sample code is appreciated, I can't seem to find any simple examples of this online.
Using the new Facebook PHP-SDK, it's very easy to accomplish this.
Requirements:
Extended Permissions, depending on your needs
Page ID
Now as I said, depending on your requirements you may need offline_access, manage_pages, but for now this is the simplest straight forward way of doing this:
After downloading the PHP SDK, and in the example.php file:
Acquire the publish_stream permission:
<fb:login-button perms="publish_stream"></fb:login-button>
After successful authentication, you post to the page wall the same way you do it for normal user profile (and with the same options too, message, picture, link, name, caption, description, source):
$page_id = '123456789';
$feed_array = array(
'message' => "Hello world!"
);
$page_post = $facebook->api("/$page_id/feed","post",$feed_array);
Result:
Please note that this approach requires you being an administrator of the page.
in this change the /me/feed/ to your page id, I did't try....Just check
$attachment = array('message' => 'some meesgae',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'mylink.com',
'description' => 'this is a description',
'actions' => array(array('name' => 'Get Search', 'link' => 'google.com')) );
$result = $facebook->api('/me/feed?access_token='.$access_token, 'post', $attachment);

Categories