我正在访问我的Angular应用程序中的Twitter搜索API,导致以下错误。将此更改实施为https。仍然得到相同的错误
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
Twitter的service.js
angular.module('TwitterServices', [], function ($provide) {
$provide.factory('$twitter', function ($http, $log) {
var consumerKey = encodeURIComponent('<consumerKey from twitter api>');
var consumerSecret = encodeURIComponent('<consumerSecret from twitter api>');
var credentials = Base64.encode(consumerKey + ':' + consumerSecret);
var twitterOauthEndpoint = $http.post(
'https://api.twitter.com/oauth2/token'
, "grant_type=client_credentials"
, {
headers: {
'Authorization': 'Basic ' + credentials, 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
}
);
twitterOauthEndpoint.success(function (response) {
serviceModule.$httpProvider.defaults.headers.common['Authorization'] = "Bearer " + response.access_token
}).error(function (response) {
});