Facebook Graph Api posting on friends wall - php

I'm having a problem when trying to post a link to a friends wall using the Facebook graph from my application.
I am currently using the Facebook SDK for PHP, I have no problems posting to the wall of the user that's logged in but cannot post to friends of the logged in user.
I have requested the extended permission "publish_stream" and here is the code am I using:
$args = array('message' => $message,
'link' => 'google.com',
'name' => 'Test!',
'caption' => 'Please click on the link',
'description' => 'description');
$result = $facebook->api("/$friendId/feed", 'POST', $args );
$friendId has the facebook id of the friend of the logged in user, any help would be much appreciated.

A quick scan of the FB API reference shows that you can set the to key value pair in this operation to
mention or target a user in this post

Related

Public posting on fan page with facebook graph api

I made a script in which automatically put in a fan page on facebook, the script works, but the post is only visible to the user who posted (which is the admin of the fan page), the login'm asking permissions below:
$loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
And I'm posting with the following code:
$args = array(
'access_token' => $page_info['access_token'],
'link' => 'http://www.sitelink.com.br/alguma-coisa',
'method' => 'post'
);
$facebook->api("/99999999999/feed","post",$args);
Does anyone know if the login I have to ask some permission to appear as the most public posts?
I have to configure something else in there in the facebook app developers?

How can I add information about read article on my site to facebook RECENT ACTIVITY?

How can I add information about read article on my site to facebook RECENT ACTIVITY (like the Guardian)?
I use php and code:
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => 'example.com',
'message' => 'Test message'
));
This code posting the message in user's timeline but I want to post message in his recent activity.
probably you wan't to use open graph api, not graph api
https://developers.facebook.com/docs/opengraph/
https://developers.facebook.com/docs/opengraph/tutorial/
https://developers.facebook.com/docs/opengraph/opengraph-approval/

programmatically login to facebook and post to page (wall)

I have a website, and I need it to post status updates to a Facebook Page from time to time.
Using my personal Facebook account, I created an App, and a Page. So far, I've been able to programmatically post to my Page's Wall, by adding this code to my website:
include_once "lib/facebook/src/facebook.php";
$facebook = new Facebook(array('appId' => 'APP_ID_HERE', 'secret' => 'APP_SECRET_HERE'));
if($facebook->getUser()) {
try {
$ret_obj = $facebook->api('/FACEBOOK_PAGE_ID_HERE/feed', 'POST', array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!',
'access_token' => 'FACEBOOK_PAGE_ACCESS_TOKEN_HERE'
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
} catch(FacebookApiException $e) {
// user logged out (has user_id, but invalid access token)
$login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
echo 'Please login.';
}
echo '<br />logout';
} else {
$login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
echo 'Please login.';
}
So I just open my website, click "Please login", login as myself. Once I'm logged it, it will now be able to post the status update to the Facebook Page.
Obviously, the problem here is that I need to be logged in for it to be able to post. If other users will try to login with their user accounts, my website cannot post status updates to the Facebook Page because I am the only Admin for the app/Page.
My question is, is there a way for me to programmatically log myself into Facebook so I can do these status updates to my Page automatically?
Sorry, total noob here to Facebook development.
Seems like you need to update status while you are offline from facebook. To do this you need to get the offline access permission of the app user and you need to have a "infinite" token for facebook app to access the APIs, so that your program can update anytime you want with out logging into facebook.
You may get something you want here
http://developers.facebook.com/docs/authentication/
I'm a little late to the party here, but I thought I'd post my gist example for how to do something very similar. I added some functionality to fbconsole to make it easy to programmatically login with fbconsole.automatically_authenticate to make it much easier to access this information in a systematic way. This addition has not yet been incorporated into the master branch of fbconsole (it was just posted this morning), but it is available here in the meantime for those that are interested.
This is what I use to do,
// = SET WALL DATA HERE ===============
$attachment = array(
'access_token' => 'My Access token here',
'message' => '',
'name' => 'My Wall Post Header/Title Here',
'caption' => 'Small caption here',
'link' => 'http://www.mywebsite.org',
'description' => 'Wall Post Details Here',
'picture' => "http://www.mywebsite.org/images/logo.gif",
);
// =POST ON FACEBOOK WALL ==========================
$this->facebook->api('/me/feed', 'POST', $attachment);
, $attachment);
So include your Facebook API, Get your Facebook Access token, SET data for your wall post and call for facebook api with me/feed method.
This will make a wall post on your wall without asking for login.
make sure you are using correct Access Token.

How to post to the wall of a fanpage with the name of the fanpage

I'm as User KDB the administrator of a fanpage TVWehen.
Switiching to the account of TVWehen I can post to the wall and orgnaize events as TVWehen ( first heading in news is TVwehen )
Usin php I can post to the wall of TVwehen ($fanpageId contains the actual value of the page )
$news=array( 'access_token' => $access_token,
'page_id' => $fanPageId,
'message' => $message,
'subject' => $name,
'caption' => 'Informationen aus dem Verein',
'description' => $description,
'picture' => $picture
);
$facebook -> api( $fanPageId . '/feed', 'POST', $news );
but the heading is not TVWehen but KDB
If I switch to the acount of TVWehen and run the php program it fails with :
"{"error":{"type":"OAuthException","message":"(#200) This post wasn't created by the application
with req_perms I tried to autorize with any possible permission .
Who has an I idea about the error or has a solution to post to a fanpage in the name of the fanpage
In summary you need to use the page's access token.
From the Facebook documentation "you must use the Page's access token, not the user access token commonly used for reading Graph API objects. This access token can be retrieved by issuing an HTTP GET to /USER_ID/accounts with the manage_pages permission. This will return a list of Pages (including application profile Pages) to which the user has administrative access, along with access_tokens for those Pages. Publishing to a Page also requires the publish_stream permission, unless otherwise noted."
http://developers.facebook.com/docs/reference/api/page/
And you can find php code (for posting a video) on the June 18th Facebook developer blog entry.
http://developers.facebook.com/blog/post/515/#video_upload

How to post to user's wall without logging in, using the new Facebook API?

I have stored a Facebook user ID and a Facebook friend ID. How can I publish to the user's wall without logging into Facebook?
I have used the old Facebook API that has UID and target_id fields like this:
$param = array(
'method' => 'stream.publish',
'callback' => '',
'message' => $row[message],
'attachment' => json_encode($attachment),
'target_id' => $row[friends_id],
'uid' => $row[sender_id],
'privacy' => ''
);
$result = $facebook->api($param);
Is this possible in new facebook PHP API?
$attachment = array('message' => $wall);
$facebook->api("/$target/feed/",'post', $attachment);
The application has wall posting permissions.
According to the docs it's also possible to post to a users feed without the "offline_permission" when the "publish_stream" permission is granted:
Comment about "publish_stream" taken from the docs:
Enables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends. With this permission, you can publish content to a user's feed at any time, without requiring offline_access.
this is possible only if you have the access_token with offline_permission granted.
if you have it, then include the token in $attachment with key "access_token"

Categories