var httpClient = Ti.Network.createHTTPClient({
onerror : function(e) {
alert(this.status + ":" + e.error);
},
onload : function(e) {
alert(this.responseText);
if (this.readyState == 4) {
var resposeText = this.responseText;
}
}
});
httpClient.open('POST', "https://api.twitter.com/oauth/request_token");
httpClient.setRequestHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8");
var now = new Date().getTime();
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var nonce = "";
for (var i = 0; i < 10; ++i) {
var rnum = Math.floor(Math.random() * chars.length);
nonce += chars.substring(rnum, rnum + 1);
}
var parameters = "oauth_callback=" + Ti.Network.encodeURIComponent("http://apicallback.stc.com.sa");
var signature = "POST&" + Ti.Network.encodeURIComponent("https://api.twitter.com/oauth/request_token") + "&" + Ti.Network.encodeURIComponent(parameters);
var header = "OAuth oauth_callback=\"" + Ti.Network.encodeURIComponent("http://apicallback.stc.com.sa") + "\",oauth_consumer_key=\"wPdlchopdYaqHhab8H8jMA\",oauth_nonce=\"" + nonce + "\",oauth_signature=\"" + signature + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + now + "\",oauth_version=\"1.0\"";
httpClient.setRequestHeader("Authorization", header);
httpClient.send(parameters);
答案 0 :(得分:1)
有几个错误:
oauth_callback
。 Authorize
标头中使用的OAuth参数必须包含在签名oauth_signature_method
”的签名方法HMAC-SHA1
来签署您的数据。您的时间戳太大了。它是Unix纪元时间以来的秒的数量,而不是毫秒数。添加“/1000
”:
var now = new Date().getTime() / 1000
更一般地,请查看有关授权请求的Twitter开发人员文档:https://dev.twitter.com/docs/auth/authorizing-request
答案 1 :(得分:0)
答案 2 :(得分:0)
appcelerator有多个推特库已经有用,我建议先从其中一个开始。
在帖子底部看到github repo的链接