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
Related
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!
A facebook user can control multiple pages. For example, a user can have their personal facebook account, their public figure page and their business page. This shows up as three distinct accounts with their own User information in facebook's server.
I want to list these things, how can I retrieve what these accounts are using the Facebook SDK?
I feel like it has to do with the Request.newMeRequest method, but this returns a GraphUser object.
and the Request.newMyFriendsRequest returns a list of users, but not a list of the personal account's connected accounts.
edit I am now using this
new com.facebook.Request(
session,
"/me/accounts",
null,
HttpMethod.GET,
new com.facebook.Request.Callback() {
#Override
public void onCompleted(com.facebook.Response response) {
if(response!=null && response.getGraphObjectList()!=null){
}
}
}
).executeAsync();
but response is null. My session has the manage_pages permission requested as well
edit I tried replacing "/me/accounts" with "/"+userId+"/accounts" and I still get back a null response. Baffling.
Insight appreciated
You can test this procedure at Graph Api Explorer -> Just click on 'Get Access Token' button-> under 'Extended permission' check 'manage_pages' & submit it. It will give you the admin-page-details JSON.
And please see Graph API Reference /{user-id}/accounts
I have integrated the Facebook SDK 3.6 in Android and I use a FQL query to fetch user data.
Following is the query I use:
if(isNetworkConnected() == true){
//Init the LoaderDialog
Asycdialog.setMessage("This might take a while and depends on the speed of your internet connection");
Asycdialog.getWindow().setGravity(Gravity.CENTER_VERTICAL);
Asycdialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
Asycdialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
Asycdialog.setCancelable(false);
//Dialog Show
Asycdialog.show();
File dir =new
String fqlQuery = "{" +
"'friends':'SELECT uid2 FROM friend WHERE uid1 = me()'," +
"'friendinfo':'SELECT uid, name, birthday FROM user WHERE uid IN" +
"(SELECT uid2 FROM #friends) AND birthday'"+
"}";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
//new Async().execute(response);
new Async().execute(response);
}
});
Request.executeBatchAsync(request);
}else{
Toast.makeText(getActivity(), "Please check and turn on your internet connection", Toast.LENGTH_LONG).show();
}
The query works exactly as intended and I get all the requested parameters.
However according to the documentation:
FQL, the Facebook Query Language, allows you to use a SQL-style interface to query data exposed by the Graph API. It provides advanced features not available in the Graph API, including batching multiple queries into a single call.
Question1) Does FQL secretly depend on Graph API - I know it is a Yes - if Yes which version of the Graph API is used when I integrate the respective SDK for iOS or Android? As again according to the Documentation change log:
Graph API
Changes from v1.0 to v2.0
App-scoped User IDs: To better protect people's information, when people log into a version of your app that has been upgraded to use Graph API v2.0, Facebook will now issue an app-scoped ID rather than that person's orginal ID. However, for users that have previously logged into your app, the user ID will not change.
App Friends: The /me/friends endpoint no longer includes the full list of a person's friends. Instead, it now returns the list of that person's friends who are also using your app.
All requests to Graph API v2.0 require an access token, except for /{id}/picture.
The format of the /me/permissions endpoint has changed. It now includes a list of permissions and a status field denoting if they were granted or declined. Link to docs
Although there is no mention of iOS or Android SDK being impacted by this, what are the measures I would have to take into consideration so that my application does not break. I am looking for answers from Authentic sources and I request the same sources to please make this documentation a bit better, come-on FB YOU can do it?
Have a look at https://developers.facebook.com/docs/apps/upgrading/#upgrading_v2_0_versions_and_path which states that
You can choose which version of the API you want to use by:
...
Integrating the Facebook SDKs for iOS or Android, which are set up to call the latest version of the API that was available on the day the SDK was released.
For people making manual calls to our API without an SDK, the version is picked by putting the version in the path when you make an API call (such as graph.facebook.com/v2.0/me).
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.
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.