Android Facebook SDK getRequestForPagedResults always null - android

I´m trying to crawl through every Picture a Page has uploaded to Facebook with Pagination. Although, the response of Facebook has got Pagination Details both in the response and in the Graph Explorer Tool, the method response.getRequestForPagedResults alwways returns null.
Does anyone know why?
Here is my code
GraphRequest request = GraphRequest.newGraphPathRequest(accessToken, "/" + timelinePhotos,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
GraphRequest nextRequest = response.getRequestForPagedResults(GraphResponse.PagingDirection.NEXT);
Log.e("HALLO", response.toString());
JSONObject obj = response.getJSONObject();
JSONArray data = null;
if(nextRequest!=null){
nextRequest.setCallback(this);
nextRequest.executeAsync();
}else{
Log.e("HI", "ICHBINFEDDIIICH");
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "photos{likes.limit(0).summary(true)}");
request.setParameters(parameters);
request.executeAsync();
Here is the response I get from facebook
01-04 04:42:03.564: E/HALLO(983): {Response: responseCode: 200,
graphObject: {"id":"853505791349630","photos":{"data":
[{"id":"1187285891304950","likes":{"summary":
{"can_like":true,"total_count":678,"has_liked":false},"data":[]}},
{"id":"1185272354839637","likes":{"summary":
{"can_like":true,"total_count":2245,"has_liked":false},"data":[]}},
{"id":"1184689078231298","likes":{"summary"
:{"can_like":true,"total_count":3242,"has_liked":false},"data":[]}}, ....lots of more IDS
"paging":{"cursors": {"after":"MTE2NzU2MDEyOTk0NDE5MwZDZD","before":"MTE4NzI4NTg5MTMwNDk1MAZDZD"},"ne
xt":"https:\/\/graph.facebook.com\/v2.5\/853505791349630\/photos?
access_token=XXX
jKzSgbusvQKMXtXmIsgl01T
vTEPQBZCp3XhM8ieGCYclmmuc7FzVDyl8jcJTW&
fields=likes.limit%280%29.summary%28true%
29&limit=25&after=MTE2NzU2MDEyOTk0NDE5MwZDZD"}}}, error: null}
So, as you can see, there clearly is a Paging-Information, so why is my nextRequest alway null?

Related

How can i get the facebook video details using facebook copy Url in android

I want to retrieve the facebook video mp4 URL and thumb images using the Facebook copy URL.I am getting 200 error for permissions while getting the video details. My code is given below.Please, anyone, help me to resolve this issue.
https://www.facebook.com/shreyaghoshal/posts/10155774118036484
request= GraphRequest.newMeRequest( AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object, GraphResponse response) {
try {
if(object!=null) {
create_facebookID = object.getString("id").toString();
Log.e("facebook" ,"id"+create_facebookID);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
create_facebookID+"_10155774118036484",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e("response", "res...." + response.toString());
}
}
).executeAsync();
}
}catch (Exception e){
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
this is the response I am getting. I want to get video URL.
10-31 10:04:45.203 27233-27233/com.tweak.tweak videos E/response: res....{Response: responseCode: 200, graphObject: {"created_time":"2017-10-09T09:12:56+0000","message":"‪I think I forgot how to breathe! Heart skipped beats. #PadmavatiTrailer is pure goosebumps. #SanjayLeelaBhansali has created the unthinkable.‬\nThe poetic magic that he alone can bring to the screens.Deepika Padukone Shahid Kapoor Ranveer Singh bring their best in this film! Music coming soon. Stay tuned.","the story":"Shreya Ghoshal shared Padmavati's video.","id":"11541726483_10155774118036484"}, error: null}
After so much time research.I got the solution. Now I can get the video details of the video. I Added keys for the bundle.Now I can get the video details.
if (Youtube_videos.fb_post_url) {
request_fb_post = new GraphRequest(
AccessToken.getCurrentAccessToken(),
create_facebookID + "_10155774118036484",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e("response", "res...." + response.toString());
}
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", "id,caption ,object_id ,permalink_url ,picture,source,status_type,properties,type ");
request_fb_post.setParameters(parameters);
request_fb_post.executeAsync();

Get All Photos from Facebook

I need to get user uploaded and tagged photos from facebook account using graph API.
I tried following code but it's give nothing to me .
GraphRequest request = GraphRequest.newMeRequest(
token,
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
// Insert your code here
Log.e("Hi "," "+response.getJSONObject().toString());
}
});
GraphRequest req = GraphRequest.newGraphPathRequest(token, "me/photos", callback);
Bundle parameters = new Bundle();
parameters.putString("fields", "id, name");
req.setParameters(parameters);
req.executeAsync();
I have given following permission to facbook.
loginButton.setReadPermissions(Arrays.asList("public_profile","user_photos"));
Thanks
Use this API
json.FB_URL+json.PAGE_ID+"?fields=albums.limit(30)%7Bname%2Cid%2Cdescription%2Cpicture%7D&access_token="+json.ACCESS_TOKEN

How to set different "limit" parameters for feed and likes in Android Facebook SDK?

I am trying to implement a method in Android by using Facebook SDK to make a GraphRequest to have the feed of the currently logged in user.
public void getMyStatusInformation(AccessToken accessToken){
GraphRequest graphRequest = new GraphRequest(
accessToken,
"/me/feed",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject responseObject = response.getJSONObject();
try {
onStatusesReceived(response);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", "likes,story");
parameters.putString("limit", "2");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
}
I want to get only last 2 posts of the user, but get all the likes of his/her friends to those posts. However, when I execute this GraphRequest, the response contains 2 posts with maximum number of 2 likes.
I tried /me/feed?limit=2, had address not found error.
Tried
parameters.putString("fields", "likes,story.limit(2)"); had the error "Story parameter does not support subfield limit"
Changed the order as:
parameters.putString("limit", "2");
parameters.putString("fields", "likes,story");
But nothing changed.
How can I do this?

How to do pagination for photos on Facebook graph data using Android-SDK?

I want to get all the photos in my profile. I want to use pagination as a query at a time returns a few results. My response has 'after' and 'before' tags. Even when I use the after parameter in my query I keep getting the same results back, no new data gets added. How should I modify my query so that I get the next set of results?
My query -
do {
Bundle parameters = new Bundle();
parameters.putString("fields", "photos{source}");
parameters.putString("after", afterString[0]);
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
Log.i("GetPhotoUrlTask", response.toString());
parsePhotoUrls(response);
}
});
request.setParameters(parameters);
request.executeAndWait();
} while (!noData[0] == true);
My response -
{Response: responseCode: 200, graphObject: {"id":"965494620","photos":{"data":[{"id":"47832732","link":"https:\/\/www.facebook.com\/photo.php?fbid=4783552732&set=a.411783262.126046.10&type=1"},
...
...
...
"paging":{"cursors":{"after":"TVRBNE16UTJOREl5TlRVeE1UQXdPakV5TnpnMU1ETTVPVGM2TXprME1EZAzVOalF3TmpRM09ETTIZD","before":"TkRjNE16STNNekkxTlRVek1EQTJPakV6TlRVMk1UQXhNekk2TXprME1EZAzVOalF3TmpRM09ETTIZD"}}}}, error: null}
How should I modify my query so that I get the next set of results?
Have a look at
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.4#paging
You should be able to get the next results with
https://graph.facebook.com/me?fields=photos{source}&after={after_token}
where {after_token} is the token coming from the last request, in your example TVRBNE16UTJOREl5TlRVeE1UQXdPakV5TnpnMU1ETTVPVGM2TXprME1EZAzVOalF3TmpRM09ETTIZD

Post image from android to facebook page

I have successfully post a feed in facebook page form the graph api.
try {
resObj.put("message","feed from android");
//resObj.put("object_attachment",bitmap);
} catch (JSONException e) {
e.printStackTrace();
}
GraphRequest request = GraphRequest.newPostRequest(
AccessToken.getCurrentAccessToken(),"363453267193844/photos",resObj,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
Log.i(TAG,"post page response::"+graphResponse);
}
}
);
request.executeAsync();
But, I'm unable to post image into facebook page. The problem is I'm unable to find the key for image attachment in Json data posted in Graph Api.
The failed response from facebook is
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 324, errorType: OAuthException, errorMessage: (#324) Requires upload file}}
Finally, finally, I was able to post an image into facebook page. This is how I did to post an photo.
Bundle bundle=new Bundle();
bundle.putByteArray("object_attachment",byteArray);// object attachment must be either byteArray or bitmap image
bundle.putString("message","some message here");
GraphRequest graphRequest=new GraphRequest(AccessToken.getCurrentAccessToken(),
"{page_id}/photos",
bundle,
HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
Log.i("post page response::" + graphResponse);
}
);
graphRequest.executeAsync();
1.) Make sure you a page access token with publish_pages permission that can be used to publish new photos.
2.) From the docs . Note that you dont have a "/" before pageid in your call.
There are two separate ways of publishing photos to Facebook:
1: Attach the photo as multipart/form-data. The name of the object
doesn't matter, but historically people have used source as the
parameter name for the photo. How this works depends on the SDK you
happen to be using to do the post.
2: Use a photo that is already on the internet by publishing using the
url parameter:
Bundle params = new Bundle();
params.putString("url", "{image-url}");
/* make the API call */
new Request(
session,
"/{page-id}/photos",
params,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
There is no way to publish more then one photo in the same graph API
call.
3.) Example ==>
Try it like this i.e post byteArrayStream of your photo
postParams = new Bundle();
postParams.putString("message", "feed from android");
postParams.putBoolean("published",true);
String pageID = "363453267193844";
//Post to the page as the page user
ByteArrayOutputStream stream = new ByteArrayOutputStream();
<YOURBITMAPPHOTOHANDLE>.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
postParams.putByteArray("source", byteArray);
postParams.putString("access_token", "your_page_access_token");
/* make the API call */
new Request(
sessionInstance,
"/" + pageID + "/photos",
postParams,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
//An error occurred during posting to facebook
FacebookRequestError error = response.getError();
if (error != null) {
isPostingError = true;
postingErrorMessage = error.getErrorUserMessage();
} else {
isPostingError = false;
}
}
}
). executeAsync();

Categories

Resources