Googlebot
Googlebot

Reputation: 15673

User access token for search via facebook graph

According to the instruction given here searching public information (as https://graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE) needs to have a valid access token. As I know access token is when a user authorized an apps to access his information; but this is searing the public information. How to get an apps access token to search public information?

In that page, facebook automatically add my access token to the link as

https://graph.facebook.com/search?q=watermelon&type=post&access_token=MY_ACCESS_TOKEN

I created an access token by my apps as https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=SECRET_ID&grant_type=client_credentials

When I use the generated access token in url https://graph.facebook.com/search?q=watermelon&type=post&access_token=GENERATED_ACCESS_TOKEN, it gives an error

{
   "error": {
      "message": "A user access token is required to request this resource.",
      "type": "OAuthException"
   }
}
  1. How can I generate access token by my apps?
  2. Or do I need to generate access token by own user account? if yes, how?
  3. Since it is searching public profile, facebook should not need authorization on every search, can I generate a permanent access token to perform different searches?

Upvotes: 12

Views: 10122

Answers (5)

naive
naive

Reputation: 31

For searching the facebook graph API using

http://graph.facebook.com/search?q=watermelon&type=post

you need a valid user access token. A user access token is different from App Access token. A user access token is created when a user authenticates your app with different access permissions which is generally close to 212 letters long.

A changes was made in the graph API in July,2013 whereby you will need to have a valid user access token to search for users and posts. The user access token could be generated by you yourself authenticating your app and generating an user access token for your app.

But the question remains, How should we generate a user app token for our apps without making other users to authenticate our apps?

Upvotes: 3

JoebeeKenobi
JoebeeKenobi

Reputation: 1

If you are searching programatically and the search URL will never be visible to the end user you can use this instead:

&access_token=app_id|app_secret

More about this here: https://developers.facebook.com/docs/facebook-login/access-tokens/

Upvotes: -2

Surabhil Sergy
Surabhil Sergy

Reputation: 2006

The Graph API Search interface has changes pending with the Q3 2013 migration. The following change will go into effect on July 10, 2013:

Graph API search changes App access tokens will be required for all search Graph API calls except Places and Pages. Search for application will no longer be supported.

https://developers.facebook.com/blog/post/2013/04/03/platform-updates--operation-developer-love/

Upvotes: 6

Oliver Piotrowski
Oliver Piotrowski

Reputation: 44

The access token you are requesting looks like an 'application' access token. This token differs from a 'user' or 'page' access token and is used for different things.

https://developers.facebook.com/docs/howtos/login/login-as-app/

This can be used to modify the parameters of your App, create and manage test users, or read your application's insights for example. App access tokens can also be used to publish content to Facebook on behalf of a person who has granted a publishing permission to your application.

Depending on what you are trying to actually do, an application token might be the wrong form of OAuth. Your example (searching for public posts with the term watermelon) doesn't require an OAuth token, so you're obviously trying a different type of graph search. Without saying what you're actually trying to access, it's impossible to actually advise you correctly.

However, I'm going to guess that you're trying to get access to graph objects that require permissions from a specific user. If that's the case, then you need to get permissions from that user first, by requesting the scope of permissions that you require.

This will give you a short term access token for that user, which will allow you to anything within the scope of permissions for which you've requested permission.

This token will only last for a short period after the user has logged into your app. It can also be promoted to a longer term access token

https://developers.facebook.com/docs/howtos/login/extending-tokens/

Upvotes: 1

Hasin Hayder
Hasin Hayder

Reputation: 818

You don't need to pass any token to search in public information (unless you want to search in user's context). Just make a call to the following url and see the URL. Please mark that I have used http instead of https.

http://graph.facebook.com/search?q=watermelon&type=post

But to make my answer more clear - with properly granted access_token I can make a call to the https version of the above url (https version requires an access token) and it just works fine without any problem.

Upvotes: -2

Related Questions