Howto use FB Graph to post a message on a page feed - php

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

Related

How to read facebook timeline with Graph API?

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.

Custom Activity Feed for Facebook Page

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.

Easy way to get facebook statuses from a particular page in PHP?

I need to grab the statuses from a Facebook page via PHP to display on the page. I don't want to have people logging in to facebook just for my script to grab the statuses from the page since it is a public page and isn't restricted. I have the Facebook API for PHP in my projects directory but have no idea how to use it to do what I want it to. Could someone give me a code example of how I'd do this? Thanks!
It's really a straight forward task if you follow the documentation. Since /PAGE_ID/feed requires any valid access_token, your app access_token is enough to get the data:
Open the Graph API Explorer (I'm querying coca-cola/feed)
Get an app access_token from the Access Token Tool and use it instead of yours
You're done!

How do I access wall posts made by the user in a facebook app

i am having trouble accessing the wall of a user. I am making a request to 'https://graph.facebook.com/'.$userID.'me/feed?access_token='.$access_token
where $access_token contains my access_token.
the strange part is that it is working well when I make the request from the application page... that is: http://apps.facebook.com/myapplication/ but when i make the same request in my callback script, it returns only those posts which are made by some application, and it does not show user's own posts like, status messages etc.
Try using the new PHP SDK, i've seen people solving bugs like yours just by changing to the SDK. It usually doesn't require you to pass the access token and supports all methods of the API (i think).
With /me/feed you can access the feed of the currently logged in user. To get the feed of some other user, you need to use their id. I am assuming that's the reason why its working in the application page and not in the script.

Why would Facebook OAuth token suddenly become invalid?

I'm using Facebook's PHP SDK, and it's been great so far. However, I have a weird issue on one page. On this page, I make a call to the graph API, then later a call using FQL. On the second call, however, I get an "Invalid OAuth 2.0 Access Token" exception. Why would the token become invalid while the first call worked? I also use FQL (same exact query/code) elsewhere in my site, and it works just fine. Does anyone know what would cause this?
Update: First call is a graph call (/me?fields=email).. second is querying for current user's affiliation, if that helps.
Could be one of several things, but if I had to hazard a guess, I'd say that you're trying to access something out-of-session, and your oauth token doesn't include the offline_access permission for the resource being accessed.
Perhaps some more detail about the nature of your API calls/FQL queries would help us narrow it down.

Categories