2014-10-07 190 views
2

我正在開發使用Google Plus的iPhone應用程序。如何使用google-plus-ios-sdk-1.7.1 sdk登錄google-plus?

當我嘗試登錄時,出現401錯誤。

我用google-plus-ios-sdk-1.7.1 sdk。

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

// Override point for customization after application launch. 

    [GPPSignIn sharedInstance].clientID = kClientID; 
    // Read Google+ deep-link data. 
    [GPPDeepLink setDelegate:self]; 
    [GPPDeepLink readDeepLinkAfterInstall];  

    return YES; 
} 

shareviewcontroller

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 


    GPPSignIn *signIn     = [GPPSignIn sharedInstance]; 
    signIn.shouldFetchGooglePlusUser = YES; 
    signIn.scopes      = @[ kGTLAuthScopePlusLogin ]; 
    signIn.delegate      = self;  

    [[GPPSignIn sharedInstance] trySilentAuthentication]; 

    _shareConfiguration     = [ShareConfiguration sharedInstance]; 
    _shareConfiguration.useNativeSharebox = YES; 
    //_shareConfiguration.deepLinkEnabled = YES; 
    _shareConfiguration.mediaAttachmentEnabled = YES; 
} 

-(void)btnGoogleShare_Action 
{ 

    if ([GPPSignIn sharedInstance].authentication) { 
     id<GPPShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog]; 
     [(id<GPPNativeShareBuilder>)shareBuilder attachImage:self.imgView.image]; 
     [(id<GPPNativeShareBuilder>)shareBuilder setTitle:self.dict[@"title"] description:self.dict[@"comment"] thumbnailURL:nil]; 
     [shareBuilder open]; 
    } 
    else 
    { 
     AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; 

     GPPSignInButton *sign = [[GPPSignInButton alloc] init]; 

     if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) { 

      appDelegate.alert = [[UIAlertView alloc] initWithTitle:@"Sign to Google +" message:@"After login to Google+, Please retry again." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Cancel", nil]; 

      [appDelegate.alert setValue:sign forKey:@"accessoryView"]; //works only in iOS7 
     } else { 

      appDelegate.alert = [[UIAlertView alloc] initWithTitle:@"Sign to Google +" message:@"After login to Google+, Please retry again.\n\n\n" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Cancel", nil]; 

      sign.frame = CGRectMake(70, 85, 100, 40); 
      [appDelegate.alert addSubview:sign]; 
     } 


     [GPPSignInButton class]; 
     [appDelegate.alert show]; 
    } 
} 



下面是截圖,誰能幫助我?


http://i.stack.imgur.com/yEv2x.png

+1

嘗試檢查此答案:http://stackoverflow.com/questions/18677244/error-invalid-client-no-application-name – 2014-10-07 12:32:13

+0

我已成功登錄,但我有另一個錯誤。「你不能同時附加鏈接和媒體到帖子。「,我怎樣才能同時分享圖片和文字? – 2014-10-07 14:13:34

+1

根據文檔https://developers.google.com/+/mobile/ios/api/protocol_g_p_p_native_share_builder-p#a9fabcb8ede280d903e1270f58e9928af,不能使用'attachImage'和'setTitle'函數。可能是'setPrefillText'將解決你的問題。 – 2014-10-07 14:45:45

回答

2

正如在評論中提到的,第一個問題已經討論here

有關文本和媒體同時發佈的第二個問題在GPPNativeShareBuilder Protocol Reference的API文檔中提及。根據此文檔,您不能使用attachImagesetTitle函數。功能setPrefillText可以解決您的問題。

相關問題