Friends email issue while getting from facebook api - android

I'm trying to get friends email addresses using facebook api like that
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions","read_stream", "email", "user_about_me", "friends_about_me", "friends_notes");
String fqlQuery = "SELECT uid, name, pic_square, contact_email FROM user WHERE uid IN " + "(SELECT uid2 FROM friend WHERE uid1 = me())";
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)
{
Log.e("log_tag", "response: "+response);
}
});
Request.executeBatchAsync(request);
But I cant get success for email but ya i am getting other values. Any one have idea about that?
I also need to get contact numbers of friends. Is it possible? Also guide me for that.
Thanks

According to the official docs:
There is no way for apps to obtain email addresses for a user's friends.
For more details: Email Permissions

Related

How to fetch userId/username with the help of Phone no in Graph Api (Facebook)?

I have gone through the following link of Facebook Graph API:
https://developers.facebook.com/docs/graph-api
But I am unable to find the API which Provides the userid/username by inputting mobile number.
My Objective:
Is there any Graph API which will find user ID/ username/profile link from a phone number?
may be you can try this to get user data:
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
Debug.trace("resultObject", object.toString());
String firstName = object.optString("first_name");
String lastName = object.optString("last_name");
String email = object.optString("email");
String socialMediaUserId = object.optString("id");
String birthday = object.optString("birthday ");
}
}
);
Bundle parameters = new Bundle();
parameters.putString(FIELDS, FB_REQUEST_PARAMETER);
request.setParameters(parameters);
request.executeAsync();
where
private final String FIELDS = "fields";
private final String FB_REQUEST_PARAMETER = "id, first_name, last_name, email,gender, birthday, location";
There is no way to get the username or the direct profile link, not even by authorizing a user. You can only get an "App Scoped ID" by authorizing the user, and his real name. There is no way to search by phone number either, you cannot even get the phone number of a user by authorizing him.

friend's birthday in android

I have written the following code to get a friend's birthday but I get null in the birthday field. Please tell me where the problem is.
String fqlQuery = "select uid, name, pic_square, birthday_date from user where uid in (select uid2 from friend where uid1 = me())";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
AccessToken myToken = AccessToken.createFromExistingAccessToken(session.getAccessToken(),
new Date(2013,6,24), new Date(10000000),
AccessTokenSource.FACEBOOK_APPLICATION_NATIVE, Arrays.asList("friends_birthday"));
//String token = "CAACEdEose0cBADB1tGwC5OA56v51uNfdMWhe6MliCaJLZBsZBzQdNobdpxyST0Ml10pwJmZBCeZCZC3RcYGSUfDEie9tTZBqMnPmOsJ7lpZBp197u9yZBUpXlDBGOQFHqwNbHwErAVRWXPi6e0WXL5hZBgDREFfZBlwEXGLWn8w407SgZDZD";
Log.e("AccessToken",myToken.toString());
params.putString("access_token",myToken.getToken());
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
Log.i("",response.toString());
}
});
Request.executeBatchAsync(request);
If some of your friends birthday's are available and some aren't it's because the latter friends decided not to provide it. If all friends are not available ensure you have friends_birthday permission
graph.facebook.com/me/permissions?fields=friends_birthday

Android Facebook SDK - Get user events

i've being able to login and get the user infos from the api with this code:
Facebook facebook = new Facebook("XX");
AccessToken token = AccessToken.createFromExistingAccessToken("XX", new Date(facebook.getAccessExpires()),
new Date(facebook.getLastAccessUpdate()),
AccessTokenSource.FACEBOOK_APPLICATION_NATIVE, Arrays.asList(permissions));
Session.openActiveSessionWithAccessToken(getActivity(), token, callback);
session = Session.getActiveSession();
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
Object proper = user.getFirstName();
System.out.println(proper);
}
});
I'm using this fixed tokens cause its always come from the same user as some sort of a host but i need to get the user events and havent seen any documentation that shows how to do it, does anyone have any idea of how to get the user events that he created?
thank you!
I've managed to achieve what i want using a FQL Query with this code:
String fqlQuery = "SELECT eid, name, pic, creator, start_time FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid='XX' and rsvp_status='attending')";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Request request = new Request(session, "/fql", params, HttpMethod.GET,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
System.out.println("Result: " + response.toString());
}
});
Request.executeBatchAsync(request);

Android Facebook SDK: does not send access token?

I'm using the following snippet to request the friendslist of the authorized user:
System.out.println("AT: " + facebook.getAccessToken());
String response = facebook.request("me/friends?fields=first_name,last_name,id,gender");
The response I get:
{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
I'm printing the accesstoken, this gives me a valid token. Also, getAccessExpires() returns a time in the future. When I request the url "me/friends" without any params, I get the expected (but with less data) friends list without errors.
How can I solve this?
String response = facebook.request("me/friends?fields=first_name,last_name,id,gender");
That is the incorrect way to use facebook.request. I'm assuming you're not using the beta Android SDK so the correct way to do this is to do the following:
Facebook facebook = new Facebook(YOUR_APP_ID);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
Bundle params = new Bundle();
params.put("fields", "first_name, last_name, id, gender");
mAsyncRunner.request("me/friends", params, new RequestListener() {
// get response here
....
});
Hope this helps.

Android and Facebook: How to use Facebook Query Language (FQL) out of Android Application

On this page facebook tells you, that you can somehow use the Facebook-Query-Language: http://developers.facebook.com/docs/reference/fql/profile
But I just dont understand what the query looks like. On Stackoverflow I just find exapmles on how to use the FQL with PHP. But I want to use it out of and Android Application. Anybody can give me URLs or Code Examples?
Using the Facebook Android SDK, an FQL call can be implemented like this:
String query = "SELECT name FROM user WHERE uid = me()";
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", query);
mAsyncFacebookRunner.request(null, params, new FQLRequestListener());
where FQLRequestListener extends RequestListener, just as for a Graph call.
See this link https://developers.facebook.com/docs/reference/fql , and you can go deeper because you can click on each element and see all the propreties of each element , ( exemple "album" here : https://developers.facebook.com/docs/reference/fql/album/ ).
This is an exemple of query to get the url of the pictures of an album by "album_id" :
String fqlQuery = "SELECT src FROM photo WHERE album_object_id="+ <your_album_id>;
This is one of the ways to call your request :
Bundle params = new Bundle();
params.putString("format", "json");
params.putString("query", fqlQuery);
params.putString("access_token", fbAccessToken);
Session session = Session.getActiveSession();
Request request = new Request(session, "/fql",
params, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(
Response response) {
Log.i(TAG, "Got results: "
+ response.toString());
}
});
Request.executeBatchAsync(request);
I hope I helped, good luck! :)
This seems to work if I put it into the Browser, but I dont know how to tell the Android Facebook SDK to use this query:
https://api.facebook.com/method/fql.query?query=select+pic_small+from+profile+where+id+%3D+USERID;&access_token=ACCESSTOKEN
I haven't tried it, but for calling fql you can try
public String request(String fql) throws FileNotFoundException, MalformedURLException, IOException {
Bundle parameters = new Bundle
parameters.putString("format", "json");
parameters.putString("query", fql);
parameters.putString("access_token", mFacebook.getAccessToken());
if (mFacebook.isSessionValid()) {
params.putString("access_token", mFacebook.getAccessToken());
}
String url = (fql != null) ? "https://api.facebook.com/method/fql.query" : "https://api.facebook.com/restserver.php";
return Util.openUrl(url, "GET", params);
}
It should work.
You have to take into acount that mFacebook is an authenticated Facebook Object (of the Facebook Android SDK). Also, that the fql sould be filled with a format supported by an url. For example:
select+pic_small+from+profile+where+id+%3D+USERID;
instead of
select pic_small from profile where id=USERID;

Categories

Resources