我正在使用 Ember.js 开发 Asana 应用程序,当我需要调用 API 时遇到了一些问题。oauth2 登录/注册运行良好,我收到了一个工作令牌(使用 curl 对其进行了测试)
我知道我需要使用“Authorization: Bearer”标头来对 API 进行身份验证,并且使用 curl 也可以很好地工作。
这是我的代码:
$.ajax({
url: 'https://app.asana.com/api/1.0/users/me',
type: 'GET',
dataType: "json",
complete: function (resp) { console.log(resp) },
error: function (jqXHR, textStatus, errorThrown) { console.log( textStatus )},
beforeSend: function (xhr) { xhr.setRequestHeader("Authorization: Bearer", "my_access_token") }
});
当我执行此代码时,出现以下错误
未捕获的语法错误:意外的令牌:我:1
解析器错误
看起来 Asana 没有回复正确编码的 JSON 文件?
这是无法解析的响应(对于格式错误的 JSON 感到抱歉)
{"data":{"id":864403617524,"name":"Sylvain","email":"my@email.com","photo":{"image_21x21":"https://s3.amazonaws.com/profile_photos/864403617524.skysUHPuO07ZftDGJSjY_21x21.png","image_27x27":"https://s3.amazonaws.com/profile_photos/864403617524.skysUHPuO07ZftDGJSjY_27x27.png","image_36x36":"https://s3.amazonaws.com/profile_photos/864403617524.skysUHPuO07ZftDGJSjY_36x36.png","image_60x60":"https://s3.amazonaws.com/profile_photos/864403617524.skysUHPuO07ZftDGJSjY_60x60.png","image_128x128":"https://s3.amazonaws.com/profile_photos/864403617524.skysUHPuO07ZftDGJSjY_huge.jpeg"},"workspaces":[{"id":498346170860,"name":"Personal Projects"},{"id":3958612780941,"name":"insideFPL"},{"id":5502245946578,"name":"Shipping Pixel"}]}}
任何帮助深表感谢。
干杯,
小号