1

我需要在 iOS 应用程序中将登录与不同的社交媒体集成。目前,一旦用户使用他的 google + 帐户登录,我正在尝试显示 UserName 和 profilePic Image。我已经按照以下 youtube 教程进行了相同的操作: http ://www.youtube.com/watch?v=M6ro0mib31M

从上面的教程中,我设法进行了登录,但我没有得到任何用户名和 profilepic,两者都返回空值。

以下是我在代码中实现的一些重要方法

//Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    GPPSignIn *signIn=[GPPSignIn sharedInstance];
    signIn.clientID=@"123456789112.apps.googleusercontent.com";
    signIn.scopes=@[kGTLAuthScopePlusLogin];
    return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    NSLog(@"openUrl=%@", url);
    if([GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation])
        return YES;

      return NO;

}

//LoginViewController.h

@interface LoginViewController : UIViewController<GPPSignInDelegate>


- (IBAction)gPlusSignIn:(UIButton *)sender;


@property (weak, nonatomic) IBOutlet UIImageView *profileImage;


@property (weak, nonatomic) IBOutlet UILabel *displayName;

@end

//LoginViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    [GPPSignIn sharedInstance].delegate=self;
    [[GPPSignIn sharedInstance] trySilentAuthentication];

}

//This method is not getting called

-(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
{
    [[[GPPSignIn sharedInstance] plusService] executeQuery:[GTLQueryPlus queryForPeopleGetWithUserId:@"me"] completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
    {
        self.profileImage.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:person.image.url]]];
        self.displayName.text=person.displayName;
        //Prints null in both
        NSLog(@"Name:%@, ProfilePic:%@",self.displayName.text,person.image.url);
    }];

}

- (IBAction)gPlusSignIn:(UIButton *)sender {
    [[GPPSignIn sharedInstance]authenticate];
}

请为此提出任何可能的解决方案。

提前致谢

4

1 回答 1

1

我能够通过在https://code.google.com/apis/console的服务选项卡下启用“Google api”来解决此问题。

于 2013-10-01T06:08:41.987 回答