I'm requesting my me/albums with:
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/albums",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
parseAlbumResponse(response);
}
}).executeAsync();
Problem is that the response object only contains 3 fields:
{
"data": [
{
"created_time": "...",
"name": "...",
"id": "..."
},
...
Instead of all fields documented here. Sames goes for /{album-id}/photos:
{
"data": [
{
"created_time": "...",
"id": "..."
},
...
Instead of this.
It was working last time I've checked but all of a sudden this strange behaviour happened.
I've tested with Facebook Graph API and the result it's the same so I guess it's not a problem from my app.
I'm using 'com.facebook.android:facebook-android-sdk:4.7.0'.
Did Facebook changed something in the requests parameters?
EDIT:
As user luschn suggested:
Declarative Fields
To try to improve performance on mobile networks, Nodes and Edges in
v2.4 requires that you explicitly request the field(s) you need for
your GET requests. For example, GET /v2.4/me/feed no longer includes
likes and comments by default, but GET
/v2.4/me/feed?fields=comments,likes will return the data. For more
details see the docs on how to request specific fields.
So I had to change my requests to:
Web console:
me/albums?fields=name, cover_photo, count and /{album-id}/photos?fields=id, images
Java:
Bundle parameters = new Bundle();
parameters.putString("fields", "id, images");
Bundle parameters = new Bundle();
parameters.putString("fields", "name, cover_photo, count");
https://developers.facebook.com/docs/apps/changelog#v2_4
Search for "Declarative Fields" in the changelog, you have to specify the fields you want to get returned.
Related
I am making a app using google Fact Check API and and the response json is like this
{
"claims": [
{
"text": "“President El-Sisi confirmed Egypt's unwavering strategic position on Libya, which aimed at restoring stability in the country, preserving its national institutions, and preventing further deterioration in Libya’s security situation via curbing illegal foreign interference in the Libyan issue.”",
"claimant": "Abdel-Fattah al-Sisi",
"claimDate": "2020-07-24T00:00:00Z",
"claimReview": [
{
"publisher": {
"name": "POLYGRAPH.info",
"site": "polygraph.info"
},
"url": "https://www.polygraph.info/a/egypt-libya-sisi-intervention/30745850.html",
"title": "Egypt's al-Sisi Told Trump Foreign Interference in Libya is Bad – Just as his Parliament Authorized him to Intervene",
"reviewDate": "2020-07-24T00:00:00Z",
"textualRating": "Misleading",
"languageCode": "en"
}
]
}
],
"nextPageToken": "CAE"
}
I want to know how can i get the urls image and display it like this
image
I can't seem to figure out how to get the image as in the JSON there is only url of the webpage.
Edit:-
Here is the code in which i am using GSON to store the values
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.i("response",response.toString());
Search search = gson.fromJson(response.toString(),Search.class);
Log.i("response",search.toString());
textView.setText("Claim:- "+search.claims.get(0).text+"\nFactual Rating:-"+search.claims.get(0).claimReview.get(0).textualRating);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.i("response",error.toString());// TODO: Handle error
}
});
If you know the exact website you can use a web scraper. Look how you can do it here.
My app uses Facebook Login Button of facebook-android-sdk.
It was working until last days, now on a graph request on a page's feed
Bundle parameters = new Bundle();
parameters.putString("fields", "id,icon,created_time,name,caption,description,message,link,full_picture,shares");
parameters.putString("limit", "50");
parameters.putString("locale", mLocale);
String pathPosts = path + "/posts";
GraphRequest request = new GraphRequest(
AccessToken.getCurrentAccessToken(), pathPosts, parameters, HttpMethod.GET,
new GraphRequest.Callback() {
#Override
public void onCompleted(
GraphResponse response) {
mResponse = response;
}
});
request.executeAndWait();
I get the OAuthException error
{Response: responseCode: 500, graphObject: null, error: {HttpStatus: 500, errorCode: 1, errorType: OAuthException, errorMessage: An unknown error has occurred.}}
UPDATE
Found that with limit lower-equal than 33 it works without errors
parameters.putString("limit", "33");
For another page's feed the limit must be lower-equal than 7 to work without errors
parameters.putString("limit", "7");
Question:
what is now the rule for the limit in a graph api request for page's feed?
Facebook Graph API has also got a Debug Mode. You need to pass an extra parameter debug=all in the REST API. It will give you the reason for the issue too in the response JSON if there is any issue.
Quoting Facebook documentation -
When Debug Mode is enabled, Graph API response may contain additional
fields that explain potential issues with the request. To enable debug
mode, use the debug query string parameter. For example:
GET graph.facebook.com /v2.3/me/friends
access_token=...&
debug=all
In your code, try changing this
String pathPosts = path + "/posts";
to this
String pathPosts = path + "/posts&debug=all";
Or
Add and an extra parameter "debug" "all" in your Bundle
and check what debug message you got
For more info on handling errors and debugging Graph API, see here - https://developers.facebook.com/docs/graph-api/using-graph-api/#errors
I am currently using thus url to test the Facebook graph API and get my page feed to display it in my application:
DOC: https://developers.facebook.com/docs/graph-api/reference/v2.2/page/feed
https://graph.facebook.com/PAGE_ID/feed?access_token=APP_ID|APP_TOKEN
(all ID obfuscated but I can share them and create a new app id needed)
So, this feed is working fine and gives me the JSON output I need:
{
data: [
{
id: "blahblah",
from: {
category: "Industrials",
name: "blahblah",
id: "blahblah"
},
message: "blahblahhttps://www.blahblah.com/",
picture: "https://fbexternal-a.akamaihd.net/safe_image.php?blahblah.jpg",
link: "https://www.blahblah.com/",
name: "Home",
caption: "blahblah",
description: "blahblah.",
icon: "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
privacy: {
value: ""
},
type: "link",
status_type: "shared_story",
created_time: "2015-01-21T12:30:37+0000",
updated_time: "2015-01-21T12:30:37+0000",
shares: {
count: 2
},
likes: {
Proble is that I want to use exactly the same feature, but instead of parsing JSON, I would like to use Facebook SDK.
This is my current code:
new Request(
null,
"/PAGE_ID/feed?access_token=APP_ID|APP_TOKEN",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
Log.e("CVE","MESSAGE: "+response.getError().getErrorMessage());
}
}
).executeAsync();
But this method gives me some authentification issues.
I get the response: "Invalid OAuth access token signature"
Any idea what is wrong and if I have to use the HTTP request instead of Facebook SDK?
As #WizKid said above, NEVER put your app_token into a client app, that is a huge security hole. Only use user access tokens in your app. Alternatively, make the request server-side, and pass it on to your client app.
You're not using the Request methods properly. If you look at the documentation for the Request class (https://developers.facebook.com/docs/reference/android/current/class/Request/), you'll see that the second parameter is "graphPath", which should be only the "path" component of a URL. You are, however, including a query string as well, which is where things break. What you should do is something like this:
Bundle params = new Bundle();
params.putString("access_token", "YOUR_ACCESS_TOKEN");
new Request(
null,
"/PAGE_ID/feed",
params,
HttpMethod.GET,
...
Alternatively, you can also use the Session object instead (to get the user access token).
I am trying to get friend list using me/frineds tag. There is no user of the app so far so i have added some frirneds as a tester of the app. But they are not showing in the response i am getting empty data list. Please guide me what i am doing wrong here. Here is the code
Bundle required = new Bundle();
required.putString("fields", "id, name, picture.type(square), gender, email");
//Request for friendlist from facebook
Request req = new Request(session, "me/friends", required, HttpMethod.GET,
new Callback() {
#Override
public void onCompleted(Response response)
{
is2=response.getGraphObject();
JSONObject json = is2.getInnerJSONObject();
readResponse(json);
String str = json.toString();
saveFileOnSD("data", str);
// generateNoteOnSD("frinedresponse", str);
Log.v(TAG, str);
}
});
Request.executeBatchAsync(req);
With v2.0, only users who are using the App too show up in the friend list. It is not enough to add someone as Tester in the App Settings, a user has to authorize your App.
See changelog for more information: https://developers.facebook.com/docs/apps/changelog
There is also "invitable_friends" and "taggable_friends", the first one is for game invitations only and the second one is for tagging only.
This has been previously asked, and the thread listed below has a ton of details. The only work around is if your app is a game. Here is the link to the other post: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app
I have made a lot of combinations to get this working but I'm always getting an empty json, however in the Graph API Explorer it works very well, I'm using this statement to get the id of the albums from a X user:
SELECT aid from album WHERE owner = XXXXXXXXXX
it is returning (for example):
{
"data": [
{
"aid": "xxxxxxx_xxxx"
},
{
"aid": "xxxxxxxx_xxx"
}
]
}
in the drop down menu (where normally is Graph Api explorer selected) I have changed for my app, also I'm using the button "get access token" and selecting: "user_photos","friends_photos","user_friends" permissions,
but in my android app only I retrieve an empty json, (note: I have used another statement to recover user data (such as birthday) with this code, and works fine so code is correct, note2: I'm using the "user_photos","friends_photos","user_friends" permissions inside the app).
the code of the app (the fragment) is:
mynewbutton = (Button) view.findViewById(R.id.mynewbutton);
mynewbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
String fqlQuery = "SELECT aid from album WHERE owner = XXXXXXXXX";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
// params.putString("access_token", session.getAccessToken());
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
//Log.i(TAG, "Result: " + response.toString());
}
});
Request.executeBatchAsync(request);
}
});
Possible the reason is cuz I'm not getting the "valid access_token" inside the app.
So it came some questions in mind:
1.-How do I get the access_token?
2.-Do I need to use the method getAccessToken()?
3.-If so, How do I integrate in my code?
4.-Is it necessary to change something in the Graph Api Explorer in order to get working well in the app?
5.- Am I missing something (a step or a piece of code for example)?
6.-In general, How do I get the aid from album inside my app just like in the Graph Api Explorer? thanks.