0

我在互联网上发现了一些信息,可以通过 WebKit 框架从 Facebook 获取访问令牌。这是真的吗?如果是,那该怎么做?

4

1 回答 1

0

您可以向 Facebook API 发布请求并取回有效的访问令牌,或者使用Facebook iOS SDK让用户登录。

-(NSString *)loadAccessToken{
    NSString *accessTokenURL = [NSString stringWithFormat:@"https://graph.facebook.com/oauth/access_token?client_id=%@&client_secret=%@&grant_type=client_credentials",client_id, client_secret];

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:accessTokenURL]];  
    [request startSynchronous];

    NSMutableString *accessMutable = [[request responseString] mutableCopy];
    [accessMutable replaceOccurrencesOfString:@"access_token=" 
                               withString:@"" 
                                  options:NSLiteralSearch 
                                    range:NSMakeRange(0, [[request responseString] length])];

    return accessMutable;
}
于 2012-09-06T13:44:22.683 回答