如何通过Google API发送POST方法? IOS

时间:2014-04-29 05:00:18

标签: ios oauth youtube-api google-api

我目前正在使用OAuth并允许用户在我的应用中登录其Youtube帐户。但是,每当我使用像这样的方法时,我似乎只能在他们的API中使用GET方法

  

https://www.googleapis.com/youtube/v3/videos/getRating?id=6HiYmLXXJA8&key=myKey

它运作正常,因为它是' GET'方法,但每当我尝试使用' POST'像这样的方法只返回"Not found"

  

https://www.googleapis.com/youtube/v3/videos/rate?id=j7e-089JOLM&rating=like&key=myKey

这是我当前的代码,它似乎只适用于GET方法

- (void)authTest {
  NSString *urlStr;
    urlStr = @"https://www.googleapis.com/youtube/v3/videos/getRating?id=6HiYmLXXJA8&key=myKeyw";


  NSURL *url = [NSURL URLWithString:urlStr];
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
  [self.auth authorizeRequest:request
            completionHandler:^(NSError *error) {
              NSString *output = nil;
              if (error) {
                output = [error description];
              } else {
                // Synchronous fetches like this are a really bad idea in Cocoa applications
                //
                // For a very easy async alternative, we could use GTMHTTPFetcher
                NSURLResponse *response = nil;
                NSData *data = [NSURLConnection sendSynchronousRequest:request
                                                     returningResponse:&response
                                                                 error:&error];
                if (data) {
                  // API fetch succeeded
                  output = [[[NSString alloc] initWithData:data
                                                  encoding:NSUTF8StringEncoding] autorelease];
                    NSLog(@"%@", output);
                } else {
                  // fetch failed
                  output = [error description];
                }
              }

              [self displayAlertWithMessage:output];
                NSLog(@"%@", output);

              // the access token may have changed
              [self updateUI];
            }];
}

请注意,我正在使用Google的OAuthSampleTouch

0 个答案:

没有答案