I'm trying to learn the way integrating facebook in your application it works.
So, until now I found out how to retrieve user's name or gender but I'm not able to found out his hometown.
Here is how I did it:
mRequestButton = (Button) findViewById(R.id.requestButton);
mRequestButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mAsyncRunner.request("me", new SampleRequestListener());
}
});
public class SampleRequestListener extends BaseRequestListener {
..........
JSONObject json = Util.parseJson(response);
final String name = json.getString("name");
final String locale=json.getString("locale");
..........
}
Now I was able to find both name
and locale
but when I do try to find the hometown doing like:
final String hometown=json.getString("hometown");
This string is empty....does anyone know how is the proper way to find the hometown???In here:https://developers.facebook.com/docs/reference/api/user/ it says that for finding out the hometown I need permissions....how I get those permissions???Can anyone tell me and posts o few lines of code?Thank u!
The hometown is another JSONObject which contains 2 strings, ID and name, so you want to extract the JSONObject called "hometown" then use json.getString("name");
to extract the name of the hometown.
Example:
public class SampleRequestListener extends BaseRequestListener {
..........
JSONObject json = Util.parseJson(response);
final String name = json.getString("name");
final String locale=json.getString("locale");
JSONObject hometown = json.getJSONObject("hometown");
final String town = hometown.getString("name");
..........
}
Why dont you output the JSON file and see what data is exposed?
Have you tried this when creating your facebook object? I think by permission they mean the fields in the permissions column on that docs page needs to go inside here:
facebook.authorize(this, new String[] { "user_hometown" },
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.