我一直在使用以下方法獲取iOS應用程序中的Facebook訪問令牌。
應用程序服務在請求標頭中包含Facebook訪問標記,請參閱https://azure.microsoft.com/en-in/documentation/articles/app-service-api-authentication/。
要訪問訪問令牌,請在Azure門戶中創建自定義API,例如, facebookUserInfo,用下面的代碼:
module.exports = {
"get": function (request, response, next) {
response.send(200, { facebookAccessToken: request.headers['x-ms-token-facebook-access-token'] });
}};
在iOS應用中,使用下面的代碼來查詢自定義API:
let client = self.table!.client
if client.currentUser != nil {
client.invokeAPI("facebookUserInfo", body: nil, HTTPMethod: "GET", parameters: nil, headers: nil, completion: { (result, response, error) -> Void in
if let resultDict = result {
if let facebookAccessToken = resultDict["facebookAccessToken"]! {
print(facebookAccessToken)
}
}
}
}
這種方法確實按預期工作,但我沒有辦法獲得Facebook令牌,以便查詢Facebook有關用戶的更多信息。 –
你在使用什麼平臺/後端? –
iOS,但客戶端應該不重要,因爲這應該發生在後端。 –