我一直在使用以下方法在 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)
}
}
}
}