我使用了来自Twitter的Anywhere和来自它的connectButton
,它将我的应用与页面和帐户相关联。如何在没有文本框的情况下立即更新我的状态?只需发送一些需要新状态字符串的请求。我找到了this官方网页:
Example Requests
POST https://api.twitter.com/1/statuses/update.json
status=Maybe%20he%27ll%20finally%20find%20his%20keys.%20%23peterfalk&trim_user=true&include_entities=true
所以我写道:
$.post('https://api.twitter.com/1/statuses/update.json', {status: 'test'}, function(res) {
console.log(res);
});
它返回 401 身份验证错误。那么,有什么想法吗?
答案 0 :(得分:3)
我认为你正在将Twitter REST API与@Anywhere库混合在一起。只有在使用oAuth对用户进行身份验证且应用程序在HTTP请求中提供oAuth密钥时,才能使用REST API。 @Anywhere库是另一个库,可以使用Javascript库为Web开发人员提供更方便的Twitter访问。
您收到401身份验证错误,因为您没有为API请求提供oAuth标头,这意味着用户未通过API身份验证。这与@Anywhere(连接按钮)的身份验证方案无关。
您必须重写代码,以便首先通过oAuth对用户进行身份验证,然后使用REST调用发布推文,或者必须使用@Anywhere库的功能为用户提供推文框。