Get facebook newsfeed in my custom Android app - android

I am creating an Android app. I integrated Facebook SDK version 4.2.0. I successfully completed Facebook login and I got the Profile Details (Profile Picture,Profile Name etc).
My requirement is that I need to bring all the news feeds from the user's account to my app. Is there any way to achieve this? I searched a lot for this.. but nothing turned up that fitted my requirement.

The graph API should do the trick!
https://developers.facebook.com/docs/graph-api/

new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
This way you can directly use it with the facebook sdk
https://developers.facebook.com/tools/explorer?method=GET&path=me%3Ffields%3Did%2Cname& with this link you can try your requests
saw that if you ask for example the posts you need a specific access token!

Related

Getting information friends on facebook

I started studying the Facebook Graph API. I would like to take a list of friends, and output personal information (general information, employment and education, and etc). How can i do this?
Friends list getting so:
AccessToken token = AccessToken.getCurrentAccessToken();
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"me/taggable_friends?name,id",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
//parse JSON
}
}
).executeAsync();
I tried use "me/friends/{Getting_higher_id}", but it's not work.
{Getting_higher_id} looks like -> AaRD2Kuv4vBnWfSaUZ2BRT2T3x4Su8MpFii4ZTB_20JwDBgQCMxZDhhLu2Cdylb-PaxZqt2mUXdAmbepjoTrKQRor2Dc
First of all, taggable_friends is for tagging friends only, you are not allowed to use it for anything else. If you just want to get information, you must use /me/friends, and you can only get friends who authorized your App too. More information: https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends
It is not possible at all to get data from friends who did not authorize your App. You can only get a limited tagging or invite token with the name of the friend for tagging or inviting friends to a game.

Facebook Friends Request - Missing Friends

I am requesting to get user friends from an Android App that I am developing. As from Facebook Api V2.0 I know that I should get only user friends that have already logged in through my App. However, although I know certain friends of a user have logged In through my App they do not appear in Facebook Request Response when requesting friends of that user. For example I get back 40 friends rather than 50+.
Has anyone experienced this behavior before? I already deleted app from few users to re-authorized it through login but I haven't see any change in the behavior.
Here is the code I'm using:
new Request(ParseFacebookUtils.getSession(),"me/friends", null, null, new Request.Callback(){
#Override
public void onCompleted(Response response) {
if (response == null){
return;
}
else if (response.getError() != null){
response.getError().getException().printStackTrace();
return;
}
GraphMultiResult result = response.getGraphObjectAs(GraphMultiResult.class);
List<GraphObject> fbInList = result.getData();
if (fbInList != null && !fbInList.isEmpty()){
for (GraphObject user : fbInList) {
JSONObject jsonUser = user.getInnerJSONObject(); // The Facebook User
System.out.println("name: " + jsonUser.optString("name"));
}
}
}
}).executeAsync();
I've found what was the problem. When I updated to the latest Facebook SDK, Facebook was returning only 25 friends. I needed to use paging or add a limit to my Friend Request. On previous SDK I didn't need to.
Adding limit:
Bundle params = new Bundle();
params.putString("limit", "50"); // Up to 5000?
friendRequest.setParameters(params);
Relevant Stack Overflow Questions:
Facebook graph API 'friends' request now only returning 25 friends per page? What's going on?
newMyFriendsRequest Facebook returns only 25 friends
Useful Facebook link for paging:
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging
The relevant portion of the doc for you is this
In v2.0 of the API I'm unable to get the full friend list of someone who has logged into my app - is there a way to get the full friend
list?
With Graph API v2.0 and above, calls to /me/friends return only the
friends who also use your app. These friends must have also granted
the user_friends permission. In the cases where you want to let people
tag their friends in stories published by your app, you can use the
Taggable Friends API. If you want to invite people to your app, we
have a number of solutions that depend on the type of app you've built
and the platforms you've built for. Please see our question about
Inviting Friends for more information.
So along with only friends using your app, they should also have authorized user_friends otherwise you wont get their details. Have you done this?

Retrieve user country through Facebook Android Graph API

I'm developing an Android application where the user can use his facebook credentials and I list some of his informations like the location. However, I noticed the format of location is something like "location:{id:335457, name: City, State}". I'd like to know if there's a way to also retrieve the user country. I saw the Facebook FQL could help, but, on current SDK version, it is deprecated. My call to the API method:
new Request(session, params, null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
// treats the response
}
}).executeAsync();
I also looked for something, but without success in my case. I'm using the latest Facebook Android SDK available.
Thank you in advance for the help.
The location field of the user is set manually and does not neccessarily mean that he's currently in that location. It's meant to be the current living location.
See
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/#fields
The call would be
/me?fields=id,location
What's returned is a page_id, for which's location you can query for with
/{page_id}?fields=id,location
The location object contains a country field.
See
https://developers.facebook.com/docs/graph-api/reference/v2.2/page

Programmatically like a facebook fan page in Facebook android SDK

I am working in an android application where I use the facebook android sdk to login to the application.I get the access token from the facebook sdk when user logged in to the application through facebook sdk.
So is it possible to like a page in facebook pragmatically having access token of a user.
It's not possible to like a page programmatically, only comments and posts. I don't know why you marked the previous answer as correct, it does not work and it's quite misleading.
To like a post on facebook, I use this part of code to create the request.
Request likeRequest = new Request(Session.getActiveSession(), pageid + "/likes", null, HttpMethod.POST, new Request.Callback() {
#Override
public void onCompleted(Response response) {
}
});
Where I already logged in to Facebook, so I can just call the Session.getActiveSession().
Then I execute the request with:
Request.executeBatchAndWait(likeRequest);
You should run this in an Asynctask, since you are not allowed to do network stuff on your main thread.

Android How to like a post with facebook 3.0 sdk

I want to implement "Like" option in my Android app, but I don't know which Request to use.
I have a valid facebook Session opened and the ID post I want to like.
How can I implement this function?
Thanks
I found a solution.
To like post I've implemented a simple POST request using likes connection of facebook post id.
This is the code:
Request likeRequest = new Request(Session.getActiveSession(), fBPostId + "/likes", null, HttpMethod.POST, new Request.Callback() {
#Override
public void onCompleted(Response response) {
Log.i(TAG, response.toString());
}
});
Request.executeBatchAndWait(likeRequest);
A cursory search (1, 2, 3) seems to indicate that it's not possible to directly "Like" things as a user via the Graph API, for security/spam reasons. One commonly-suggested alternative has traditionally been to show a Facebook-controlled "Like" button in a WebView and include that in your application instead.
However, more recently, the Facebook developer guide has provided one possible solution for how you can implement "like"-style functionality in your app when it comes to publishing stories on the user's behalf, though it's not precisely the same thing as what you seem to be asking for.

Categories

Resources