【问题标题】:Extracting Facebook profile picture提取 Facebook 个人资料图片
【发布时间】:2012-10-08 10:11:36
【问题描述】:

我正在 Windows 8 中构建 Metro 应用程序,我希望它能够与 Facebook 同步。 我想在我的 jsp 文件中显示图片。用户点击他收到的facebook通知后,jsp文件将呈现出来。

当我只问用户的名字时,我成功了,但当我问个人资料图片时,我遇到了障碍。

我为 Facebook 创建了一个 XMLHTTPRequest,Facebook 将作为响应“JFIF”发送给我。

function getFacebookPicture(facebookUser) {
    var request = new XMLHttpRequest();
    var str = "https://graph.facebook.com/" + facebookUser.id + "/picture";
    request.open("GET", str, false);
    request.send();
    var response = request.responseText;
    return response;
}//getPic()

响应 = "JFIF"。

我收到并发送通知。

 function sendNotification2() {

    var uid = facebookUser.id;
    var picture = getFacebookPicture(facebookUser);


    var request = new XMLHttpRequest();
    var appID = "XXXXXX"; // the app id
    var appSecret = "YYYYYYYY"; // the app secret 
    var notificationContent = "YO yo yo"; // the message on the notification.
    var str = "https://graph.facebook.com/" +
        uid + "/notifications?access_token=" +
        appID + "|" + appSecret + "&href=?name=" + facebookUser.name +"?picture="+ picture + "&template=" +notificationContent + "&method=POST&format=json";

    request.open("GET", str, false);
    request.send();
    var response = request.responseText;
}

我得到的错误是

{
   "error": {
      "type": "OAuthException",
      "message": "An access token is required to request this resource."
   }
}

我在我的应用中添加了以下权限:read_friendlists、manage_notifications、publish_stream、offline_access、user_photos 登录时。

那么我怎样才能得到图片呢?

谢谢。

【问题讨论】:

    标签: javascript facebook jsp profile image


    【解决方案1】:

    当您查询此 URL 时 -

    https://graph.facebook.com/USER_ID/picture
    

    你没有得到图像的“路径”。你得到图像本身。我不确定您是如何实现个人资料图片的,但我知道在常规网页上,只需将该 URL 放在 <img> 标记的 src 中即可。

    <img src="https://graph.facebook.com/4/picture" width="50" >
    

    【讨论】:

      【解决方案2】:
      function getFacebookPicture(facebookUser) {
          return "https://graph.facebook.com/" + facebookUser.id + "/picture";
      }//getPic()
      

      开始阅读here,了解如何获取访问令牌。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-20
        • 1970-01-01
        • 2012-06-08
        • 1970-01-01
        • 2017-09-30
        • 2014-03-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多