这是权限
fb.authorize(MainActivity.this,new String [] {email,user_location,user_birthday,publish_stream},新的DialogListener ){ public void onFacebookError(FacebookError e){ // TODO自动生成的方法存根 Toast.makeText(getApplicationContext(),+ e,Toast.LENGTH_SHORT ).show(); e.printStackTrace(); } public void onError(DialogError e){ // TODO自动生成的方法stub //Toast.makeText(getApplicationContext(),Error,Toast.LENGTH_SHORT).show(); } public void onComplete(Bundle values){ // TODO自动生成的方法stub 编辑器编辑器= sp.edit(); editor.putString(access_token,fb.getAccessToken()); editor.putLong(access_expires,fb.getAccessExpires()); editormit(); updateButtonImage(); } public void onCancel(){ // TODO自动生成的方法stub Toast.makeText(getApplicationContext(),取消,Toast.LENGTH_SHORT )。显示(); } }); }感谢谁来帮助高级人员。
解决方案Graph API Explorer工具是查看图形API端点的响应的好方法。通过点击获取访问令牌,查看/ me的输出,请求正确的权限(例如 user_location )。当我使用 user_location 权限获取访问令牌时,我可以看到我当前的
developers.facebook/tools/explorer/?method=GET&path=me
要获取当前位置,请执行以下操作:
String currentCity = obj.getJSONObject(location)。getString(name);使用较新的SDK,您可以通过传递如下API API对象
$来获取位置详细信息b $ b graphObject.getInnerJSONObject()。getJSONObject(location)。getString(id)
I'm using Facebook SDK in my Android App. And I need to get all the information of the user. By now I'm able to get the Name ID Email Birthday and the profile pic of the user. The last one that I need to get is the location or current location of the user. I'm using this code below.
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("graph.facebook/"+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); } }Here are the permissions
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()); editormit(); updateButtonImage(); } public void onCancel() { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "Cancel", Toast.LENGTH_SHORT).show(); } }); }Thanks for who will help in advanced.
解决方案The Graph API Explorer tool is a great way to see what the response of a graph API endpoint is. Just request the right permissions (such as user_location) by clicking "Get Access Token" and see the output of '/me'. When I get an access token with the user_location permission I am able to see my current
developers.facebook/tools/explorer/?method=GET&path=me
To get the current location, this is how to do it:
String currentCity = obj.getJSONObject("location").getString("name");With newer SDKs you can get location detail by passing as below with graph API object
graphObject.getInnerJSONObject().getJSONObject("location").getString("id"))
更多推荐
Graph API从Android SDK中的Facebook SDK获取位置
发布评论