【问题标题】:issue in getting facebook profile data in android在 android 中获取 facebook 个人资料数据的问题
【发布时间】:2014-04-16 07:39:59
【问题描述】:

我通过 Facebook sdk 开发了一个具有 Facebook 登录功能的应用程序,我正在处理用户个人资料数据,如用户名、ID、位置、个人资料图片、生日、电子邮件 ID,因此我获得了所有数据,但在获取个人资料图片时遇到了问题路径所以我的代码有什么问题

代码

mAsyncRunner.request("me", new AsyncFacebookRunner.RequestListener() {
   @Override
   public void onComplete(String response, Object state) {
      Log.d("Profile", response);
      String json = response;
      try {
          JSONObject profile = new JSONObject(json);
          final String name = profile.getString("name");
          final String sex = profile.getString("gender");
          final String id = profile.getString("id");
          final String email = profile.getString("email");
          final String location = profile.getJSONObject("location").getString("name");
          final String birthday = profile.getString("birthday");
          final String picture = profile.getString("picture");

          Log.i("=-=-=-=-=-=-=-=-=-=-=-=-=-",name+ "-------"+sex+"---------" +id+"---------"+email+"---------"+location+"---------"+birthday+"---------"+picture +"---------");
      } catch (JSONException e) {
          e.printStackTrace();
      }
}

出现错误:-- org.json.JSONException: 图片没有值

【问题讨论】:

  • 你的意思是,你没有得到picture
  • 是的,我没有收到图片的回复

标签: android facebook facebook-graph-api android-facebook


【解决方案1】:

要获取picture url,您不需要从Graph API 中获取它(我认为picture 字段无效),您可以随时使用此url-

https://graph.facebook.com/{user-id}/picture

查看this 文档了解更多信息。

所以只需从您的代码中删除这一行(因为 picture 键在 json 中不存在)-

final String picture = profile.getString("picture");

获取位图-

URL imgUrl = new URL("http://graph.facebook.com/{user-id}/picture?type=large");
InputStream in = (InputStream) imgUrl.getContent();
Bitmap  bitmap = BitmapFactory.decodeStream(in);

编辑:

如果特别需要图片网址(不推荐也不需要)-

final String picture = 
        profile.getJSONObject("picture").getJSONObject("data").getString("url");

【讨论】:

  • org.json.JSONException: 图片没有值
  • 你没有得到我。 https://graph.facebook.com/{user-id}/picture 就是头像的url 就是这样!你不需要任何json!
  • 大声笑,这就是我一遍又一遍地告诉你的,它只是图片网址(它会自动重定向到个人资料图片)- 请参阅:graph.facebook.com/sahilmittal/picture
  • 我想获取这个 url 并存储在数据库中 { "id": "1573711670", "name": "Pranav Lathigara", "picture": { "data": { "is_silhouette":假,“网址”:“fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t5.0-1/…”} } }
  • 你不应该!如果 facebook 更改图像存储怎么办?如果你还想我会添加如何,检查编辑
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-20
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 2011-04-16
  • 2015-11-25
  • 1970-01-01
相关资源
最近更新 更多