请使用以下代码在 Google Plus 中获取访问令牌
首先替换你- GTMOAuth2Authentication.h文件中的(NSString *)description方法,你肯定会得到 G+ 访问令牌
- (NSString *)description
{
NSArray *props = [NSArray arrayWithObjects:@"accessToken",nil];//[NSArray arrayWithObjects:@"accessToken", @"refreshToken",@"code", @"assertion", @"expirationDate", @"errorString",nil];
NSMutableString *valuesStr = [NSMutableString string];
NSString *separator = @"";
for (NSString *prop in props) {
id result = [self valueForKey:prop];
if (result)
{
[valuesStr appendFormat:@"%@",result];
separator = @", ";
}
}
return [NSString stringWithFormat:@"%@",valuesStr];
}
在 .h 文件中
@class GPPSignInButton;
@interface GPlusView : UIViewController <GPPSignInDelegate>
{
IBOutlet GPPSignInButton *signInButton;
}
@property (retain, nonatomic) IBOutlet GPPSignInButton *signInButton;
在 .m 文件中
signInButton_.shouldFetchGoogleUserEmail = TRUE;
signInButton_.delegate = self;
signInButton_.clientID = [SamacharAppDelegate clientID];
signInButton_.scope = [NSArray arrayWithObjects:
@"https://www.googleapis.com/auth/plus.me",
nil];
-(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
{
if (error) {
NSLog(@"Error = %@",error.localizedDescription);
return;
}
NSLog("Auth Data = %@",auth);
/* Auth Data = {accessToken="ya29.AHES6ZQYLmSBc9n4pLj9U8OQrFoTDZnGLH8okPkxbda7B0Q", refreshToken="1/puItTB-sqHupfp9qPCKcb6_gWUjgcxwzc9TKJvUwMEI", expirationDate="2012-11-24 13:30:55 +0000"} */
}