My problem is that I want to know the users that uninstall my facebook application. I have set a callback url for facebook to hit when someone uninstalls the app and all I get is a signed request POST variable which, according to facebook documentation should be a base64 json encoded object but it seems impossible to trace the user's facebook id in there. Actually it's more like random data.. :| Anybody knows how to parse this thing to get the fb uid?
I tried:
<?php
$data = json_decode(base64_decode($_POST['signed_request']));
?>
And still I don't get something valuable out of it..
Check this documentation on facebook: http://developers.facebook.com/docs/authentication/signed_request/
Especially the "Verifying and Decoding" section, where you will find code to decode your signed_request parameter.
Related
I am trying to like a Facebook post posted from an account. I have the oauth token of the account but i cant figure out how to like a post from my php code. I have a facebook app and also have the app id and app secret for my facebook app. I want to do this using the PHP SDK Version 5.0.0.
Can anyone please help with this or direct me to the some documentation apart from the one here - https://developers.facebook.com/docs/reference/php/5.0.0
Thanks
Surprisingly enough the approach that i commented on Navin's answer worked just fine now.When i had tried it previously i had gotten a 'Url not recognised' error.
My code is as follows-
$test=array();
$like=$fb->post('/'.$post_id.'/likes',$test,$token);
In the $like variable i get an object of FacebookResponse with a status of success or failure.
I believe creating Facebook service is not an issue. Once created, you may set a default access token for easier access. You may then take the id of the post you want to like and do this -
$response = $fb->post('/'.$post_id.'/likes');
EDIT after Tushar's comment
$response = $fb->post('/'.$post_id.'/likes', array());
where $fb is a Facebook service with a default access token.
Hope this helps.
I need to read facebookk timeline and some tutorial says me to read with API Graph and I use:
https://graph.facebook.com/***/posts?access_token=***
but when I use this code I obtain {data[]} . I don' know how I wrong. Anyone can help me?
You question is pretty broad.
Did you use the Facebook API explorer? Found here
Are you sure the token is valid?
I am pretty sure what you are doing wrong is your call above is un-versioned so it will default to v2.0+. Which means you can't query based on user name. Next if you are using a user Id in the middle *** it will return empty because that user hasn't authorized the app that got the token, and/or has decided to hide themselves from open graph calls. You can use a public page ID in that spot to get that page posts.
Give this a try
https://graph.facebook.com/ME/posts?access_token=***
Provided you have a valid token it should work with unversioned calls. I suggest you play with the API explorer linked above.
Research and Reasoning
I haven't worked on a Facebook Application for a while, thus am a little rusty with how the Graph API works.
I have had a look at various topics and pages such as:
https://developers.facebook.com/docs/reference/plugins/activity/
How to Style Facebook Activity Feed
From what I can gather, getting the activity of a facebook page is pretty simple, however, before I proceed, there are a few things I would like to iron out before to ensure I build the app or write the script in the best possible way...
My Question
I would like to gather the status updates of a Facebook Like page and then feed this data to my News page on the website I am building.
My method would be a simple call to the Graph API to gather the data, and then display it on screen.
My question is, can I do this without creating a Facebook App, and therefore do I even need the PHP SDK?
Is it possible to achieve it like so and are there any request limits:
$url = 'https://graph.facebook.com/LIKE_PAGE_ID/feed';
$result = json_decode(file_get_contents($url));
If the above is the correct answer to this question then please let me know and I will close this question
Update
I have tried the above URL with my like page and it says that I need an Access Token. This is what I feared... Is it possible to get this data without being logged in, and without having set up a Facebook Application?
Why not create a Facebook app and use App Access Token to retrieve the feed for the Public pages.
Though you might get feed of some pages without app access token or response for different end points without access_token, but as the Facebook's API is constantly changing, and would finally settle with authorized request to their end points, I would suggest you to use the App Access Token which is can be created with the format
App_ID|App_Secret
So instead of your call for $url that you had you can change it to
$url = 'https://graph.facebook.com/LIKE_PAGE_ID/feed?access_token=App_ID|App_Secret';
Which you can then json_decode. Also there is nothing on binding to use PHP SDK, and in your case, it is not even required.
I have created an app, and now i want to post a message on one of my pages wall with use of the new Graph API. Is this do-able?
below is the steps which i do
Using this to Get access code
https://www.facebook.com/dialog/oauth?client_id=1498653617947&redirect_uri=https://apps.facebook.com/post_on__my_page/index2.html&scope=email,read_stream,publish_stream,manage_pages,offline_access
Than use this to get access token
https://graph.facebook.com/oauth/access_token?client_id=1498653617947&redirect_uri=https://apps.facebook.com/post_on__my_page/index2.html&client_secret=seceret&code=AQDCqJNJnCvnFKVdbCyTp2vfzbT0ADbNgYsQ_2YtDdC_O2aIOwvkjx52HNcp3uiuBANJqOhb_M2sptB-lRrIECZxi5kZpzljez1J1oOtTp25gTnNDmV-RCVvR97DMiRAprNtwUBcstAotjsyYo5cNwJCWnkcgNigwhbQtE5Jp22sluVcZKhnO43cWQE#_=_
Now get page id and page access token from below
https://graph.facebook.com/me/accounts/?access_token=the_access_token_above
*use this to post on my page *
https://graph.facebook.com/1916117518646/feed?message:testmessage&access_token=aceess_token
any one please explain which point is wrong because instead of posting is just show posts details
i found that some thing wrong in this below code any one please suggest what and how to do
https://graph.facebook.com/1916117518646/feed?message:testmessage&access_token=aceess_token
I always highly suggest to people experimenting around for the first time to use the Graph API Explorer tool. It helps solidify the structure of the Graph and how to access it. See https://developers.facebook.com/tools/explorer
Another thing I always recommend is to lint the access_token you are trying to use. See https://developers.facebook.com/tools/lint. This is to ensure you have the right token with the correct permissions.
Also the access_token you use to post to a page must be a page token and not a user token. In your above example, it's unclear as to which one you're using since you've named both the same. I know you said you're using it, but with that variable name being the same, I always wonder.
Also the you need to do an HTTP Post and not an HTTP get to post a message. Again, play around in the graph API explorer until you can do it there. Once you've done it there, it's fairly trivial to do it with one of the SDKs.
You need to perform POST request, not GET, and pass parameters in POST body, not in the url
http://developers.facebook.com/docs/reference/api/user/#posts
http://facebook.stackoverflow.com/questions/691425/how-do-you-post-to-the-wall-on-a-facebook-page-not-profile
I am working to post some content to user's wall from my website.
I created an application on facebook.
Should I manually create a dialog box redirecting user to something like that?
http://www.facebook.com/dialog/oauth/?
scope=email,user_birthday&
client_id=123050457758183&
redirect_uri=http://www.example.com/response&
response_type=token
How can I check if user already connected application on my website?
Should I store any of the user's facebook data when he allows my application to remember if already connected?
Data comes like that as told in http://developers.facebook.com/docs/reference/dialogs/oauth/
http://www.example.com/response#
access_token=...&
expires_in=3600
Then how can I post some contect with PHP?
I read something here but cant understand actually...
http://developers.facebook.com/docs/reference/api/post/
Any help appreciated
Thanks
Did you check out the PHP SDK? There's an example showing how to authenticate a user in there and to post to the wall, check out the "graph()" (which you cannot call directly, you can call "post" directly on the facebook class if I recall, see the "_call()" method) method and check out the documentation again.
Let me know if that helps otherwise we'll take it from there.
Facebook session parameters will help you to found out whether user in connected to your app or not.
e.g. if you are using php-sdk
$session = $facebook->getSession();
if($session)
//do something
else
//do something
I find the PHP SDK for "viral" channel convoluted and a poor user experience. Checking if the user has "auhtorized" your app is easy, as was pointed out already. But if the user hasn't, then requesting authorization is a lot of back and forth communication (http://developers.facebook.com/docs/authentication/). That's before you can post to their wall. Which still requires redirects if done from the server (http://developers.facebook.com/docs/reference/dialogs/).
I find it a lot easier to use the javascript SDK. Check if they have authorized your app (FB.getLoginStatus), if not then ask for authorization (FB.login), then use FB.ui to post to their own wall or a friend's wall. It's all done client side, no calls back to the server necessary, no page reloads or redirects.