我如何在Imgur API中进行授权?

问题描述 投票:1回答:1

我希望您能帮助我解决这个问题。我试图创建一个应用程序,并且需要上传和下载图像,所以我决定使用Imgur Api,但是在授权部分遇到了麻烦。

根据文档(https://apidocs.imgur.com/),我必须先注册才能获取我的客户ID和客户密码,此步骤已完成。但是,当我尝试授权以获取刷新令牌时,它将失败。我使用get方法调用此URL:

https://api.imgur.com/oauth2/authorize?client_id=MyId&response_type=token

这是我得到的错误

error:
error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse 
(<anonymous>) at XMLHttpRequest.onLoad 
(http://localhost:4200/vendor.js:7457:51) at 
ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask 
(http://localhost:4200/polyfills.js:2743:31) at Object.onInvokeTask 
(http://localhost:4200/vendor.js:36915:33) at 
ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask 
(http://localhost:4200/polyfills.js:2742:36) at 
Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask 
(http://localhost:4200/polyfills.js:2510:47) at 
ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as 
invoke] (http://localhost:4200/polyfills.js:2818:34) at invokeTask 
(http://localhost:4200/polyfills.js:3862:14) at 
XMLHttpRequest.globalZoneAwareCallback 
(http://localhost:4200/polyfills.js:3888:17)
text: "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric"

非常通用,所以我不知道我在做什么错

顺便说一句,我认为不重要,但是我的应用程序在Angular 5中,以防万一:

authorize(){
  let url=`https://api.imgur.com/oauth2/authorize?client_id=${this.client_id}&response_type=token`;

  console.log(url)
  this.http.get(url).subscribe((resp:any)=>{
    console.log(resp);
  });
}

我希望你能指导我!

谢谢!

angular rest api authentication imgur
1个回答
0
投票

响应是一个HTML页面,因此您不能使用任何JSON解析方法对其进行解析。

此外,令牌在URL中返回,不在响应中。

© www.soinside.com 2019 - 2024. All rights reserved.