I have an app which uses the Facebook PHP SDK. It used to be a simple matter to post to a user's Facebook wall. I would do the authentication, and then something like:
$ret_obj = $Facebook->api('/me/feed', 'POST',
array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!'
));
and on their wall the link would appear. Since Timeline was introduced, however, this doesn't seem to work. I don't get an error, I just don't get anything back. I can't find any helpful documentation on how this should work.
More info
I don't get any error, I just get "NULL" returned in $ret_obj.
If I do something like
$ret_obj = $Facebook->api('/me', 'GET');
then it works fine - I get the user's information back. So it's connecting ok, just not posting.
Double check that you have allowed publish_stream permission.
You can refer to PHP SDK and JavaScript SDK Feed Dialog for more examples.
Official Documentation: http://developers.facebook.com/docs/reference/dialogs/feed/
Related
I´m building a facebook app with php,
everything works perfect, I do successful dialog auth
I have the short_live token
I generate the long_live_token and save it to some directory
what I want to do is that in canvas app the user selects some stuff and activates a mechanism that regularly posts stuff, this is why I save the token.
but what can I do with it?!
I find a lot about generating the access_token but nothing about how to use it!?
Where can I add it as parameter? What is the key?
example:
I´m using facebook sdk for php for post sth. to a wall like
$msg_body = array(
'message' => "wassup yo"
);
$facebook->api($uri, 'post', $msg_body );
but this only works if
$facebook->getUser();
is returning a user
how can I use my stored access_token to do the same?
I believe there is a function called "setAccessToken" in the Facebook PHP SDK. You would just need to set it with that function and it gets added to every call automatically.
Manual way:
$params = array(
'message' => 'wassup yo',
'access_token' => '[your-token]'
);
$facebook->api($uri, 'post', $params);
You could also do this with CURL, this would be an example URL;
$url = 'https://graph.facebook.com/' . $userId .
'/feed' .
'&access_token=' . $accessToken .
'&message=' . $userMessage;
Basically you just add the Access Token as a parameter like the message.
Just make sure you are using secure calls, see this article for an example of using CURL with the Facebook API and usage of "appsecrect_proof": http://www.devils-heaven.com/extended-page-access-tokens-curl/
IMPORTANT: Be sure that the message parameter is always 100% user generated without any prefilling (see Platform Policy) and keep in mind that you need to go through a review process with pulish_actions to make it available for other Users: https://developers.facebook.com/docs/apps/changelog
I am trying to get facebook php sdk v4 to work with my app. I am using Drupal and an nginx server with phpfpm.
When I try to get the session from facebook sdk, I get the error - Missing redirect uri parameter. While debugging, I found 2 strange things are happening -
1) If I copy and paste the get url(generated by the sdk) in my browser, a valid access token is returned.
2) If I change the method for retrieving the access token from GET(default) to POST in the sdk, a valid access token is returned to my app.
Also, when using the access token I received from POST call, if I make further GET requests to the graph api, none of them work.
However, if I make a POST request, such as posting to my wall, it works.
Also it should be noted that the sdk is internally using curl to make all requests.
Edit :
Code Example -
To generate login url
$helper = new \Facebook\FacebookRedirectLoginHelper($this->redirectUrl);
$loginUrl = $helper->getLoginUrl(array('public_profile', 'email', 'user_friends', 'publish_actions'));
Now the person is taken to facebook for authentication and redirected to my redirect url. Here the code is -
$helper = new \Facebook\FacebookRedirectLoginHelper($this->redirectUrl);
$session = helper->getSessionFromRedirect();
Since getSessionFromRedirect internally uses a GET call, it doesn't work for me. When I change the sdk code to use POST, a valid access token is returned.
Also when I get a valid session using a POST request, this works
$response = (new FacebookRequest(
$session, 'POST', '/me/feed', array(
'link' => 'www.example.com',
'message' => 'User provided message'
)
))->execute()->getGraphObject();
But this doesn't work -
$user_profile = (new FacebookRequest(
$session, 'GET', '/me'
))->execute()->getGraphObject(GraphUser::className());
echo "Name: " . $user_profile->getName();
Clearly there seems to be an issue with all the GET requests. Any hints on what can be the problem?
Solved the problem finally. Turns out drupal is changing the & in url for GET requests to & .
Related to this .
I use following code to update the status:
$parameters = array(
'message' => "Hey guys check this cool app",
'link' => "http://apps.facebook.com/xxxx",
'name' => "Invitation for xxxx",
'picture'=>"http://localhost:55/xxxx/logo.jpg",
'caption' => "Try xxxx!",
'access_token'=>$at //valid access token
);
try{
$statusUpdate = $facebook->api('/me/feed', 'POST', $parameters);
}catch(FacebookApiException $e){}
This works and after status update, I get an id. But when i go to my profile and check the status update, This is what I see:
. The problems are: (1) Image is not displayed, and (2) Unwanted My first app as shown in figure. Why is this happening? How do i fix it?
http://localhost/... is never going to work as the image location because Facebook won't be able to retrieve it. Put the publicly accessible URL to the image in that field instead.
In the screenshot you posted, the 'My first app' part is the name of the app, you can change this in the app settings. It can't be changed on a per-post basis, all posts from your app are attributed to your app
As far as the image is concerned, check again that the path of the image is correct. If it still does not work, try specifying 'https' instead of http and see what happens
I have written an Application what posts Photos on a FanPage into a Specific Album long time ago.
Now I didn't used for a half year. Now I had to set up the Application again and grant the extended Permissions to the Fan Page (streamm_publish) again.
But now I've a Problem, I'm using the old REST API what now gives me the error: An unknown error ocurred with the error code 1.
Then I tried to post throught the Facebook Graph api.
I tried to make a call to the Api /pageid/albumid/photos what's not working(Unknown path components)
I tried to makea a call to /albumid_from_my_page/photos then the Photos were posted to my profile
I tried to upload it to /pageid/photos what is the same as the one above
But the code fpr the REST Api worked well, what's the problem there, and why the new Graph Api isn't working how she should?(BUG?)
To post a photo to an album, this is the code:
$post_data = array(
"message" => "My photo caption",
"source" => '#' . realpath($file)
);
$album_id = "XXXXX";
$facebook->api("/$album_id/photos", 'post', $post_data);
Now I suppose to interact with the page albums you need a page access_token added to your $post_data array, for this check this answer.
You need take ACCESS_TOKEN page...
try:
http://graph.facebook.com/me/accounts?access_token= GET THIS TOKEN USING GRAPH API... OR MAKE USING the getAccessToken()...
and will see all pages and aplications that u have, find just application for this case and COPY TOKEN... and damn!!!
It's possible to see this token thought GRAPH API EXPLORER...
regards.
I'm using the php SDK for the Graph API, and everything is working fine-getting usernames, uploading photos etc.
However, when I'm trying to publish to the current user's feed, it just makes the page get stuck.
This is the code:
$publish_feed = $facebook->api('/'.$userid'/feed', 'post', array(
'message'=> 'message',
'picture'=> 'http://mysubdomain.mywebsite.com/photo.jpg',
'link'=> 'http://apps.facebook.com/appname/'
););
I've tried:
Putting the code in different places in the code-no matter where I do, it gets the page stuck, Even if ti is at the end of the code, it gets it stuck, and nothing shows.
changing $userid to /me. No success.
Please help.
Make sure you have the publish_stream permission
use /me or api("/$userid/feed",..etc
Remove the extra column:
Code:
$params = array(
'message' => 'message',
'picture'=> 'http://mysubdomain.mywebsite.com/photo.jpg',
'link'=> 'http://apps.facebook.com/appname/'
);
$publish_feed = $facebook->api("/$userid/feed", "post", $params);