首页 \ 问答 \ YouTube API v3无效的凭据访问令牌(YouTube api v3 Invalid Credentials access token)

YouTube API v3无效的凭据访问令牌(YouTube api v3 Invalid Credentials access token)

尝试在OAuth 2.0中使用Youtube API时,我收到401 Invalid Credentials错误。

我使用google登录sdk并使用params获取access_token:

    GIDSignIn *sharedSignIn = [GIDSignIn sharedInstance];

sharedSignIn.shouldFetchBasicProfile = NO;

sharedSignIn.scopes = [NSArray arrayWithObjects:
                       @"https://www.googleapis.com/auth/youtube.force-ssl",
                       @"https://www.googleapis.com/auth/youtube",
                       @"https://www.googleapis.com/auth/youtube.readonly",
                      // @"https://www.googleapis.com/auth/youtube.upload",
                       nil];

[sharedSignIn signIn];

比我使用AFNetworking库进行GET请求

- (void) getInformationWithParams: (NSDictionary *) params
                       method: (NSString *) method
                    onSuccess: (void(^)(NSDictionary *responseObject)) success
                    onFailure: (void (^) (NSError *error)) failure {

[self.requestOperationManager GET:method
                       parameters:params
                         progress:nil
                          success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {

                              NSLog(@"%@", responseObject);

                              if (success) {
                                  success(responseObject);
                              }

                          }
                          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                              NSLog(@"getInformationWithParams Error: %@", error);

                              if (failure) {
                                  failure(error);
                              }

                          }];

}

以前我做过baseURL init

        NSURL *baseURL = [NSURL URLWithString:@"https://www.googleapis.com/youtube/v3"];
    self.requestOperationManager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];

最后我得到了请求

    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                     @"snippet",   @"part",
                     @"true",   @"home",
                      myApiKey, @"key",
                        myAccessToken, @"access_token",
                        nil];

[[SMServerManager sharedManager] getInformationWithParams:params
                                                   method:@"activities"
                                                onSuccess:^(NSDictionary *responseObject) {

                                                }
                                                onFailure:^(NSError *error) {

                                                }];

我不明白我做错了什么。

PS:如果他们不需要使用acces_token请求工作。


I am getting 401 Invalid Credentials error trying to use the Youtube API in the OAuth 2.0.

I used google sign in sdk and get access_token with params:

    GIDSignIn *sharedSignIn = [GIDSignIn sharedInstance];

sharedSignIn.shouldFetchBasicProfile = NO;

sharedSignIn.scopes = [NSArray arrayWithObjects:
                       @"https://www.googleapis.com/auth/youtube.force-ssl",
                       @"https://www.googleapis.com/auth/youtube",
                       @"https://www.googleapis.com/auth/youtube.readonly",
                      // @"https://www.googleapis.com/auth/youtube.upload",
                       nil];

[sharedSignIn signIn];

Than I used AFNetworking library for GET request

- (void) getInformationWithParams: (NSDictionary *) params
                       method: (NSString *) method
                    onSuccess: (void(^)(NSDictionary *responseObject)) success
                    onFailure: (void (^) (NSError *error)) failure {

[self.requestOperationManager GET:method
                       parameters:params
                         progress:nil
                          success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {

                              NSLog(@"%@", responseObject);

                              if (success) {
                                  success(responseObject);
                              }

                          }
                          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                              NSLog(@"getInformationWithParams Error: %@", error);

                              if (failure) {
                                  failure(error);
                              }

                          }];

}

previously I did baseURL init

        NSURL *baseURL = [NSURL URLWithString:@"https://www.googleapis.com/youtube/v3"];
    self.requestOperationManager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];

and in the end I get request through

    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                     @"snippet",   @"part",
                     @"true",   @"home",
                      myApiKey, @"key",
                        myAccessToken, @"access_token",
                        nil];

[[SMServerManager sharedManager] getInformationWithParams:params
                                                   method:@"activities"
                                                onSuccess:^(NSDictionary *responseObject) {

                                                }
                                                onFailure:^(NSError *error) {

                                                }];

I don't understand what I'm doing wrong.

PS: Requests work if they don't need to use acces_token.


原文:https://stackoverflow.com/questions/35870665
更新时间:2019-10-10 02:37

最满意答案

这是一个非常愚蠢的错误。 我在几个谷歌帐户中感到困惑,并为项目制作错误的文件。


It was a very stupid mistake. I'm confused in several google accounts and make wrong files for project.

2016-03-08

相关问答

更多

如何处理来自sqlite的返回在离子2中选择语句?(How to process the return from sqlite Select statement in ionic 2?)

我同意Suraj Rao的异步结果。 我想补充一点,你可以在Promise.all()中完成所有创建表。 当在'then'语句之间时,在查询上放置一个'return',在下一个“then”中预期结果。 例如: query.then( (res) => { return query2 } ).then( (res2) => { do something } ).catch( (err) => {...}); 在你的情况下: let db = new SQLite(); console.

如何从Unix发送一封电子邮件,其中包含10个文件中的3个文件行数,大小和日期(How to send an email from Unix with 3 files row count, size and date among 10 files)

这是一个重构得很好的Awk脚本,可以一次完成所有操作。 awk 'BEGIN { print "Subject: Numbers for this month\n"; print "Hi All,\n\nPFB file details\n" print "----------------------------------" print "|filename |rowcount |size |" print "---

C中的矩阵错误(Matrix Error in C)

for(i=0; i=y; y++){ for(j=0;j=k; k++){ 请参阅这些bot h循环及其条件i=y和j=k 。 您可以为它们分配警告所针对的值。 可能这样做 - for(i=0; i<y; i++){ for(j=0;j<k; j++){ 和这个 - if(∗(∗(m+i)+j)==number){ 这些不是用于取消引用指针的运算符。 使用*进行解除引用 - if(*(*(m+i)+j)==number){ // or simply write m[i

Python Jupyter Notebook:将两个直方图子图并排放在一个图中(Python Jupyter Notebook: Put two histogram subplots side by side in one figure)

是的,这是可能的。 请参阅以下代码。 %matplotlib inline import matplotlib.pyplot as plt import numpy as np list1 = np.random.rand(10)*2.1 list2 = np.random.rand(10)*3. bins = np.linspace(0, 1, 3) fig, ax = plt.subplots(1,2) ax[0].hist(list1, bins, alpha = 0.5, color

如何为clojurescript创建宏(how to create macros for clojurescript)

这是一个允许您在编译时将文件包含在cljs中的宏。 例如,在执行i18n时,我将所有语言字符串保存在translations.edn文件中。 然后我在编译时使用/clj/test_app/macros.clj中的宏包含它: (ns test-app.macros (:import java.io.File)) (defmacro load-edn "Reads a file and returns it as a string" [relative-path] (slurp r

HTML,Bootstrap和CSS 3(HTML, Bootstrap and CSS 3)

考虑到这个CSS: .stickToBottom { position: fixed; bottom: 0; } 您需要使用javascript检测垂直滚动是否存在: function isVerticalScrollPresent() { return document.documentElement.scrollHeight !== document.documentElement.clientHeight; } 如果此函数返回false,则将“stickToBot

无法访问ActiveMQ管理页面/ admin /。(Unable to access ActiveMQ admin page /admin/. Reason: Unauthorized)

似乎你试图在没有登录的情况下访问该页面。要登录:转到localhost:portNo / admin portNo = 8161如果没有修改您将被提示登录弹出用户名:admin密码:admin以上是默认值。 如果是错的,请查看conf / jetty-realm.properties文件。 希望它有帮助。 It Turned out to be Browser issue. It worked on Internet Explorer and not on Chrome

用ggplot创建浮动饼图(create floating pie charts with ggplot)

饼图按定义使用极坐标。 你可以在另一个使用笛卡尔坐标的图形上叠加一些饼图,但它可能很糟糕。 事实上,无论如何,饼图总是很糟糕,所以要小心你想要的东西。 coord_polar页面上的coord_polar 。 该代码中的重要一点是指定该半径映射到“y”美学。 df <- data.frame( variable = c("resembles", "does not resemble"), value = c(80, 20) ) ggplot(df, aes(x = "", y =

相关文章

更多

最新问答

更多
  • 如何在给出字符串的开始和结束部分时使用正则表达式提取字符串的一部分(How to extract a part of a string using regex, when starting and ending portion of the string is given)
  • 使用从下拉列表派生的变量作为select语句中的列名... Access DB(Using a variable derived from a drop-down list as the column name in a select statement … Access DB)
  • 禁用付款选项 - 仅限特定产品 - magento的货到付款(Disable payment options-only cash on delivery for particular product-magento)
  • Python:Spyder在未停靠的编辑器窗口和spyder控制台之间切换(Python: Spyder switching between undocked editor window and spyder console)
  • 使用proxy_pass会影响letsencrypt的安装吗?(Will using proxy_pass affect letsencrypt installation?)
  • 即使confirm()方法为false,jquery AJAX也会提交表单(Jquery AJAX submits the form even if confirm() method is false)
  • 我可以使用带有params关键字的lambda表达式吗?(Can I use a lambda expression with params keyword?)
  • 以编程方式在swift中格式化字符串(Programmatically formatting string in swift)
  • 如何根据现有因素在新列中添加因子(How to add a factor in a new column according to the existing factors)
  • android快速加载来自网址的图片(android fast load image from url)
  • yii CHtml ::按钮和POST请求到控制器(yii CHtml::button and POST request to controller)
  • 无法更改工具栏的颜色(Can't change the color of toolbar)
  • android ListIterator,类转换bug?(android ListIterator, class casting bug? please check my log)
  • 当我使用函数创建属性时,如何向R data.frame添加属性?(How do I add an attribute to an R data.frame while I'm making it with a function?)
  • 如何将我的数据存储到Activity类中的一个对象中,并将该对象发送到另一个Activity类(How to store my data into one object in my Activity class and send that object to another Activity class)
  • 无法在wamp服务器上的joomla安装中配置数据库(Unable to configure database in joomla installation on wamp server)
  • 捕获所有重复的组(Capture all repeated groups)
  • 为宏提供状态更新,直到完成后进入无响应状态(Providing status updates for macro that goes into not responding state until completion)
  • 如何让PDO Fetch()以字符串形式返回(How to get a PDO Fetch( ) to return as string)
  • 无法访问SDK工具来安装NDK(Can't access SDK Tools to install NDK)
  • 获取CGPoint与应用程序窗口进行比较(Get CGPoint in comparison to app Window)
  • 如何在css中对齐图像和文本?(How to align images and text in css?)
  • BinaryWriter将脏字符放在AppendMode的开头写入[重复](BinaryWriter puts dirty chars at the begin writing in AppendMode [duplicate])
  • Jquery垂直内容滚动条(Jquery Vertical content scroller)
  • 是否有可能在android studio中更改.so文件代码并进行构建?(Is it possible to change the .so file code in android studio itself and make a build?)
  • prolog避免重复谓词(prolog avoiding duplicate predicates)
  • 在Swift中使用AlamoFire创建通用方法(Creating a generic method with AlamoFire in Swift)
  • 如何获得给定的JSON值?(how to get given JSON value?)
  • 访问当前对象的类(Access class of current object)
  • 如何延迟jQuery中的文本功能(How to delay the text function in jQuery)