问题描述:

Im having trouble converting the curl command to angularjs $http request. Im not sure if im doing it correctly do you guys have any advice. # Note when I use the curl command its working I did not include the oauth credientials for privacy issues

Sample Angular Code:

var req = {

url: 'https://api.twitter.com/1.1/statuses/user_timeline.json',

headers: {

'Authorization': 'OAuth oauth_consumer_key="xxxxx",oauth_signature_method="HMAC-SHA1",oauth_timestamp="xxxx",oauth_nonce="xxxx",oauth_version="1.0",oauth_token="xxxxx",oauth_signature="xxxxxx',

},

}

return $http( req ).then( function(response) {

console.log(response);

}

Response :

data: null

status: -1

config: { "method": "GET", "transformRequest": [ null ], "transformResponse": [ null ], "url": "https://api.twitter.com/1.1/statuses/user_timeline.json", "headers": { "Authorization": "OAuth oauth_consumer_key=\"xxxxx\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"xxxxx\",oauth_nonce=\"xxxxx\",oauth_version=\"1.0\",oauth_token=\"xxxxxxxx\",oauth_signature=\"xxxx", "Accept": "application/json, text/plain, /" }}

Working using the curl command below -

curl -X GET -H 'Authorization:OAuth oauth_consumer_key="xxxxx",oauth_signature_method="HMAC-SHA1",oauth_timestamp="xxxx",oauth_nonce="xxxx",oauth_version="1.0",oauth_token="xxxx",oauth_signature="xxxxx"' https://api.twitter.com/1.1/statuses/user_timeline.json

相关阅读:
Top