FacebookAuthorizationException' with message Unsupported get request - Facebook PHP API - php

This url:
https://graph.facebook.com/v2.2/389546181070007/feed?access_token={token}&appsecret_proof={secret}&fields=name
And:
https://graph.facebook.com/v2.2/186726524843032/feed?access_token={token}&appsecret_proof={secret}&fields=name
have both valid pageID's and the same access_token and appsecret. The token I'm getting with:
https://graph.facebook.com/oauth/access_token?client_id={app_id}&client_secret={app_secret}&grant_type=client_credentials'
Yet the first one throws an exception and the second one works fine and returns the feed list.
The exception thrown is: FacebookAuthorizationException' with message 'Unsupported get request.
Have tried to use a different app and more things... been struggling with this issue for 6 hours now.
Has anyone any idea how it is possible that one page works and the other doesn't?

When I try to visit the first page on Facebook, I only get “Sorry, this page isn't available”.
That means that either that page is not published yet, or has some access restrictions in place. In both cases, you can not “see” it via API, when you use an app access token.
You will need to use either a page access token for that page, or a user access token for a user that has the right to see the page.

Related

Facebook Access Token Invalid for search endpoint

i am making this request through graph api and i am getting this error:
(#200) Must have a valid access_token to access this endpoint
A couple of days ago i was making the same requests without any problem and now i keep getting this error messages, i don't know why. the query i am requesting is the following:
/search?q=SOMETHING&type=event&fields=id,name,description,cover,start_time,end_time,location,owner,venue&limit=5000&access_token=ACCESS_TOKEN.
This query works on graph api explorer (including the access token). My question is, the error is mine or from facebook?
Thanks.
Put the Access Token in the Debugger and check if it´s valid: https://developers.facebook.com/tools/debug/
If yes, file a bug: https://developers.facebook.com/bugs/

Get Facebook User's real id using App Scoped Id

I know this question already has been discussed, But I'm here with a different way and a confusion.
First : if I do debugging in Graph API Explorer it returns different app_scoped_user_id and it return me correct json when I run graph.facebook.com/$app_scoped_user_id but with my app it generate different App Scoped ID which don't works with above method. Why that happen?
Second : I thought to get last redirect url using CURL but it returns http://www.facebook.com/login.php?next=http://www.facebook.com/app_scoped_user_id/$app_scoped_user_id . Now I've two thoughts (may be stupid thoughts),
Can I open that app scoped url in a popup window and get that window url after redirection and close the popup?
Can I login in Facebook anyhow using CURL so that i can get real user_id?
I know, app scoped user id can be used. But I want to give it a try.
Warning: Facebook old API in use
There's a way to get it, but you won't like it:
get the user to log in to your app via Facebook
make a second call to the API using the retrieved access token to get their username
https://graph.facebook.com/me?access_token={THE_ACCESS_TOKEN}
make a third call to that username without an access token to get their Facebook id
https://graph.facebook/{USERNAME} <= No access token here!
EDIT: sorry, old API is used here.

Foursquare invalid grant error

i am new to foursquare and i wish to have autofill textbox by foursquare api. For this i referred to https://developer.foursquare.com/overview/auth and have registered my app with foursquare. When I write
https://foursquare.com/oauth2/access_token
?client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
&grant_type=authorization_code
&redirect_uri=YOUR_REGISTERED_REDIRECT_URI
&code=CODE
in browser url (all parameters replaced), i get the following error:
{
"error": "invalid_grant"
}
How do i solve this? How do i implement autofill textbox?
Extending pfhayes answer: CODE is not a constant. Your are supposed to actually replace it with a real code.
It can get confusing, because at some point during the auth flow, there are constants such as code and access_token that should be taken exactly ad in the example.
The code you supply must be the code returned by a successful user authorization, as seen here: https://developer.foursquare.com/overview/auth. When a user authorizes your app with foursquare, they will be redirected to your page with a code HTTP parameter. This code will be the code you exchange for a valid access token.

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

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

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