1

After Google authorization I try to post a moment without any confirmations:

GTMOAuth2Authentication *auth;
auth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:TMH_SOCIAL_GOOGLE_KEYCHAIN
                                                             clientID:TMH_SOCIAL_GOOGLE_CLIENTID
                                                         clientSecret:TMH_SOCIAL_GOOGLE_SECRET];
if ([auth canAuthorize]) {

    NSString *postString = @"{\"type\":\"http:\\/\\/schemas.google.com\\/AddActivity\",\"target\":{\"id\":\"tmhabc\",\"type\":\"http:\\/\\/schemas.google.com\\/AddActivity\",\"description\":\"First post description\",\"name\":\"First post\"}}";

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.googleapis.com/plus/v1/people/me/moments/vault?access_token=%@&key=%@", auth.refreshToken, TMH_SOCIAL_GOOGLE_APIKEY]];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    GTMHTTPFetcher *myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];

    [myFetcher setAuthorizer:auth];
    [myFetcher setPostData:[postString dataUsingEncoding:NSUTF8StringEncoding]];

    [myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData, NSError *error) {
        if (error == nil) {
            NSLog(@"OK %@", [[NSString alloc] initWithData:retrievedData encoding:NSUTF8StringEncoding]);
        } else {
            NSLog(@"%@", error.localizedDescription);
        }
    }];
}

But receive an error 401: The operation couldn’t be completed. (com.google.HTTPStatus error 401.)

I try this:

  1. Grant permissions for Google Plus in Apis Console
  2. Authorize with the scope "https://www.googleapis.com/auth/plus.login"
  3. In the Web found only this answer: http://gusclass.com/blog/2013/02/27/common-issues-for-the-new-google-platform-release/ guy in this post suggests to use "data-requestvisibleactions" (but how to do this in objective c)

I don't know what is wrong.

Update

https : //developers.google.com/+/api/latest/moments/insert#try-it does not work for moment insert.

RuslTG
  • 41
  • 8
  • Have you upgraded to the latest Google+ iOS SDK (1.2.1) released a few days ago? Your code appears to be setting things manually rather than using the provided methods. – BrettJ Mar 01 '13 at 16:53
  • BrettJ, yes I tried to use Google+ SDK https://developers.google.com/+/mobile/ios/share but it opens confirm dialog every time when I want to share. This is not convinient to use. – RuslTG Mar 04 '13 at 06:09
  • @RuslTG How did you add the "request_visible_actions" parameter in iOS?? – Supertecnoboff Jun 06 '14 at 11:11

1 Answers1

2

Got the same problem but on server side. Your oauth request should include request_visible_actions parameter while redirecting user to authentication page. Checkout my question and diff for php client.

Community
  • 1
  • 1
mente
  • 2,746
  • 1
  • 27
  • 33
  • "request_visible_actions" is worked! But ... the moment did not appeared on the stream. – RuslTG Mar 04 '13 at 07:20
  • Very strange, http://wheresgus.com/appactivitiesdemo/ is not post the moment also. – RuslTG Mar 04 '13 at 07:54
  • how do you check whether it was posted? – mente Mar 04 '13 at 09:25
  • I received 200 OK response. Then went to my Google+ account and saw nothing. – RuslTG Mar 04 '13 at 11:03
  • 1
    View Profile -> About, Check Apps in the bottom of the page. There will be your app and when you click on it you will get activity for it. Don't ask why it's hidden so deep. – mente Mar 04 '13 at 11:40
  • Oh my god, this is too hard to understand. Thanks guys for your help. – RuslTG Mar 04 '13 at 11:57
  • Moments are not published to the stream, they are [published to your profile](https://plus.google.com/apps/activities) and only visible to those who you've given permission during the authentication flow to see. – BrettJ Mar 05 '13 at 18:43
  • @RuslTG How did you add the "request_visible_actions" parameter in iOS?? – Supertecnoboff Jun 06 '14 at 11:11