在request param里直接设置fields的参数串中添加location是不会生效的
//"fields"
private static final String DEFAULT_REQUEST_VALUE = "id,name,location,link,picture,email,devices";
需要在登陆的Permission中添加”user_location”,如下:
List<String> permissions = Arrays.asList("user_location","public_profile");
LoginManager.getInstance().logInWithReadPermissions(activity, permissions);
然后再在requestParam中添加fields的字段如前文所述:
//send request and call graph api
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
HashMap<String, String> responseMap = new HashMap<>();
try {
parseJSONResponse(object, responseMap);
} catch (Exception e) {
e.printStackTrace();
}
final HashMap<String, String> postMap = responseMap;
// response callback
responseHelper.onSuccess(responseMap);
}
});
// bundle the fields you want to get, sent the request
Bundle parameters = new Bundle();
if (TextUtils.isEmpty(paramsRequestKey) || TextUtils.isEmpty(paramsRequestKey)) {
setRequestParams();
}
parameters.putString(paramsRequestKey, paramsRequestValue);
request.setParameters(parameters);
request.executeAsync();
转载署源-By-KyleCe:http://blog.csdn.net/KyleCeshen/article/details/50381721