gpt4 book ai didi

android - Graph Api 未从 Android 中的 Facebook SDK 获取位置

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:40:07 26 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用 Facebook SDK。我需要获取用户的所有信息。到目前为止,我已经能够获取姓名 ID 电子邮件生日和用户的个人资料照片。我需要获取的最后一个是用户的位置或当前位置。我在下面使用这段代码。

if(fb.isSessionValid()){
button.setImageResource(R.drawable.logout_button);

JSONObject obj = null;
URL img = null;


try {
String jsonUser = fb.request("me");
obj = Util.parseJson(jsonUser);
String id = obj.optString("id");
String name = obj.optString("name");
String bday = obj.optString("birthday");
String address = obj.optString("location");
String email = obj.optString("email");
((TextView) findViewById(R.id.txt)).setText("Welcome! "+name);
((TextView) findViewById(R.id.txtbday)).setText("Birthday: "+bday);
((TextView) findViewById(R.id.txtaddress)).setText("Address: "+address);
((TextView) findViewById(R.id.txtemail)).setText("Email: "+email);
img = new URL("http://graph.facebook.com/"+id+"/picture?type=normal");
Bitmap bmp = BitmapFactory.decodeStream(img.openConnection().getInputStream());
pic.setImageBitmap(bmp);

} catch (FacebookError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



}else{
button.setImageResource(R.drawable.login_button);
}
}

这里是权限

fb.authorize(MainActivity.this,new String[] {"email", "user_location", "user_birthday","publish_stream"}, new DialogListener() {

public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), ""+e, Toast.LENGTH_SHORT).show();
e.printStackTrace();
}

public void onError(DialogError e) {
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}

public void onComplete(Bundle values) {
// TODO Auto-generated method stub
Editor editor = sp.edit();
editor.putString("access_token", fb.getAccessToken());
editor.putLong("access_expires", fb.getAccessExpires());
editor.commit();
updateButtonImage();
}

public void onCancel() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Cancel", Toast.LENGTH_SHORT).show();
}
});
}

感谢谁会在后期提供帮助。

最佳答案

Graph API Explorer 工具是查看图形 API 端点响应的好方法。只需通过单击“获取访问 token ”请求正确的权限(例如 user_location)并查看“/me”的输出。当我获得具有 user_location 权限的访问 token 时,我能够看到我当前的

https://developers.facebook.com/tools/explorer/?method=GET&path=me

获取当前位置,方法如下:

String currentCity = obj.getJSONObject("location").getString("name");

使用较新的 SDK,您可以通过如下方式传递图形 API 对象来获取位置详细信息

graphObject.getInnerJSONObject().getJSONObject("location").getString("id"))

关于android - Graph Api 未从 Android 中的 Facebook SDK 获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13373794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com