使用Google身份验证订阅Youtube频道(目标C)

时间:2015-08-24 18:24:14

标签: ios objective-c youtube google-api

下午好。

我使用您的示例:https://github.com/googlesamples/google-services授权Google并获取订阅以订阅Youtube频道。 为此,请使用以下函数:

-(void) subscription{

    NSString *channelId = @«MyChannelId»;
    NSString *api_Key = @«MY_IOS_API_KEY»;

    AFHTTPRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];

    NSString *URLString = [NSString stringWithFormat:@"https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key=%@", api_Key];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    NSString *authValue = [NSString stringWithFormat:@"Bearer %@", [GIDSignIn sharedInstance].currentUser.authentication.accessToken];
    NSLog(@"Access Token: %@", [GIDSignIn sharedInstance].currentUser.authentication.accessToken);

    [requestSerializer setValue: authValue forHTTPHeaderField:@"Authorization"];

    [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    manager.requestSerializer = requestSerializer;
    NSDictionary *parameters = @{@"snippet":@{
                                     @"resourceId":@{
                                             @"channelId":channelId,
                                             @"kind":@"youtube#channel"
                                             }
                                     }
                             };
    [manager POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@«OK:»);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@«Faild:»);
    }];
}

然后传输在

中获得的值
- (void) receiveToggleAuthUINotification:(NSNotification *) notification {

    if ([[notification name] isEqualToString:@"ToggleAuthUINotification"]) {
        [self subscriptionBtn];   
    }
}

我从失败块中收到以下错误:

error =     {
    code = 403;
    errors =         (
                    {
            domain = usageLimits;
            extendedHelp = "https://console.developers.google.com";
            message = "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.";
            reason = ipRefererBlocked;
        }
    );
    message = "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.";
};

0 个答案:

没有答案