2

I am developing an iPhone application using Google Plus.

When I try to login, I get a 401 error.

I used 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;
}

In the 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];
    }
}



Below is a screenshot, can anyone help me?


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

LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
James Chan
  • 97
  • 2
  • 12
  • 1
    Try to check this answer: http://stackoverflow.com/questions/18677244/error-invalid-client-no-application-name – Michael Zhavzharov Oct 07 '14 at 12:32
  • I have got success for login, But I have got another error."You cannot attach a link and media to a post at the same time.", How can I share image and text at the same time? – James Chan Oct 07 '14 at 14:13
  • 1
    According to documentation https://developers.google.com/+/mobile/ios/api/protocol_g_p_p_native_share_builder-p#a9fabcb8ede280d903e1270f58e9928af you can't use 'attachImage' with 'setTitle' function. May be 'setPrefillText' will resolve your issue. – Michael Zhavzharov Oct 07 '14 at 14:45
  • Really thanks, I have solve all my problem. – James Chan Oct 07 '14 at 18:37
  • 1
    If you solved it according to my comments, then I better post them as an answer and it will be good if you accept it. Otherwise, post your solution for your problem, and accept it, not to leave question without an answer. – Michael Zhavzharov Oct 07 '14 at 18:43

1 Answers1

2

As it mentioned in the comments, first problem is already discussed here.

Second problem about text and media simultaneously post is mentioned in API documentation for GPPNativeShareBuilder Protocol Reference. According to this documentation you can't use attachImage with setTitle function. Function setPrefillText could resolve your issue.

Community
  • 1
  • 1
Michael Zhavzharov
  • 1,727
  • 13
  • 26