我正在尝试使用pub-sub方法订阅特定用户的事件。我能够成功验证用户,但是当我调用pub-sub url时,我收到以下错误。
{"meta":{"error_detail":"Unsupported API version 1.1, unless called with an OAuth header","code":404,"error_type":"endpoint_error","time":1480394928,"message":"Not Found","user_xid":""},"data":{}}
代码: 此代码在OAuth2.0身份验证的成功回调中调用。
var subscription_url = "https://jawbone.com/nudge/api/v.1.1/users/@me/pubsub?webhook=https://*****/pushJawbone";
$http.post(
subscription_url, {
headers: {
'Authorization': "Bearer " + accessToken
}
}
).success(
function(response) {
console.log("Jawbone User Subscription Successful" + response);
}
).error(
function(error) {
console.log("Jawbone sub unsucessful: " + JSON.stringify(error));
}
)
答案 0 :(得分:0)
问题不在于Jawbone API。问题出在角度$ http方法中。由于某些原因,上面的代码根本没有发送标题,所以OAuth错误。 当我使用下面的代码时它工作正常。
$http({
method: 'POST',
url: subscription_url,
headers: {
'Authorization': 'Bearer ' + accessToken
}
}).success(
function(response) {
console.log("Jawbone User Subscription Successful" + response);
}
).error(
function(error) {
console.log("Jawbone sub unsucessful: " + JSON.stringify(error));
}
)
感谢Ray的所有帮助。