这就是我目前从facebook接收access_token的方式,目前正在考虑为mac创建一个简单的Facebook客户端。
NSString *clientId = @"********";
NSString *scope = @"read_stream";
NSString *urlString = [NSString stringWithFormat:@"https://www.facebook.com/dialog/oauth?"
"client_id=%@"
"&redirect_uri=https://www.facebook.com/connect/login_success.html"
"&scope=%@"
"&response_type=token", clientId, scope];
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
NSURLConnection *conn = [[[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES] autorelease];
[req release];
然后我拿起didReceiveResponse委托:
-(void)connection:(NSURLConnection *)connection didReceiveResponse: (NSURLResponse *)response
{
NSString *urlString = [[response URL] absoluteString];
int accessTokenStartPosition = [urlString rangeOfString:@"access_token="].location + 13;
int accessTokenEndPosition = [urlString rangeOfString:@"&"].location;
NSRange accessTokenRange = NSMakeRange(accessTokenStartPosition, accessTokenEndPosition - accessTokenStartPosition);
NSString *accessToken = [urlString substringWithRange: accessTokenRange];
int expiryStartPosition = [urlString rangeOfString:@"expires_in="].location + 11;
int expiryEndPosition = urlString.length;
NSRange expiryRange = NSMakeRange(expiryStartPosition, expiryEndPosition - expiryStartPosition);
NSString *expiryTime = [urlString substringWithRange: expiryRange];
NSLog(@"Test: %@", accessToken);
NSLog(@"Test: %@", expiryTime);
}
我不确定这是否是最好的方法,也不想使用iOS的Facebook SDK,有没有更好的方法,或者我走对了路?
发布于 2013-05-01 18:30:49
你也可以使用Facebook提供的FBGraph API for IOS,这是非常方便和方便的使用,你可以得到完整的教程新的基于oAuth 2.0版本的FBGraph API,Get the tutorial here
https://stackoverflow.com/questions/16309117
复制相似问题