Reputation: 18712
I want to write a Java program, which runs a Facebook Graph Search query like "Find all people from city X, who like Y".
For now, I want to get the data about the page Y.
To do this, I wrote following code:
final Facebook facebook = new FacebookFactory().getInstance();
facebook.setOAuthAppId("...", "...");
facebook.setOAuthAccessToken(new AccessToken("..."));
final AccessToken oAuthAccessToken = facebook.getOAuthAccessToken();
try {
final ResponseList<Page> pages = facebook.searchPages("Costume jewelry");
LOGGER.debug("oAuthAccessToken: " + oAuthAccessToken);
} catch (FacebookException e) {
LOGGER.error("", e);
}
When running this code, I get following exception:
22:56:38.405 [main] DEBUG f.internal.http.HttpResponseImpl - {"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190}}
22:56:38.481 [main] ERROR c.a.f.FbCustomerProfiler -
facebook4j.FacebookException: message - Invalid OAuth access token.
code - 190
Relevant information for error recovery can be found on the Facebook Developers Document:
https://developers.facebook.com/docs/graph-api/using-graph-api/#errors
at facebook4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:179) ~[facebook4j-core-2.1.0.jar:2.1.0]
at facebook4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65) ~[facebook4j-core-2.1.0.jar:2.1.0]
at facebook4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:93) ~[facebook4j-core-2.1.0.jar:2.1.0]
at facebook4j.FacebookImpl.get(FacebookImpl.java:2584) ~[facebook4j-core-2.1.0.jar:2.1.0]
at facebook4j.FacebookImpl.searchPages(FacebookImpl.java:2256) ~[facebook4j-core-2.1.0.jar:2.1.0]
at facebook4j.FacebookImpl.searchPages(FacebookImpl.java:2251) ~[facebook4j-core-2.1.0.jar:2.1.0]
at myproduct.FbCustomerProfiler.run(FbCustomerProfiler.java:32) [classes/:na]
at myproduct.FbCustomerProfiler.main(FbCustomerProfiler.java:20) [classes/:na]
Disconnected from the target VM, address: '127.0.0.1:50651', transport: 'socket'
I took those examples from the Facebook4J site. The only difference between my code and theirs is that in my version I do not call facebook.setOAuthPermissions(commaSeparetedPermissions);
.
Therefore I suppose that missing permissions are the cause of the error.
What permissions do I need in order to run a query, which returns the data (most importantly - the ID of the page, which I can use in the next query) about a page?
Upvotes: 0
Views: 2105
Reputation: 31479
To search for Pages, you need to pass an App Access Token with your request according to the Facebook docs:
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0#search
Searches across Page and Place objects requires an app access token.
You can use
{app_id}|{app_secret}
for that.
BTW, your original question "Find all people from city X, who like Y" will not work, because you're not able to query this kind of info from FB.
Upvotes: 1