2012-10-08 275 views
-1

我正在Windows 8中構建一個metro應用程序,我希望它能與Facebook同步。 我想在我的jsp文件中顯示圖片。用戶點擊他收到的facebook通知後,將會顯示jsp文件。提取Facebook的個人資料圖片

當我只問我成功的用戶的名字,但當我問我的個人資料圖片我面臨的障礙。

我爲Facebook和Facebook創建了一個XMLHTTPRequest作爲響應「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() 

response =「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當我登錄

所以,我怎麼能得到照片?

謝謝。

回答

1

當查詢該網址 -

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

你沒有得到的「路徑」的形象。你得到的圖像本身。我不確定您是如何實現個人資料照片的,但我知道在常規網頁上,只需將該網址放置在<img>標記的src即可。

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

+0

謝謝,但我沒有工作。 – Aviade

0
function getFacebookPicture(facebookUser) { 
    return "https://graph.facebook.com/" + facebookUser.id + "/picture"; 
}//getPic() 

開始閱讀here找出如何獲得訪問令牌。

+0

謝謝,但我沒有工作。 – Aviade

+0

什麼不起作用?你有沒有得到正確的訪問令牌? –

相關問題