我试图在Flash中使用一个简单的应用来查看用户的推文。
我相信'我已经正确获得了访问令牌。
var bearerToken:String;
var consumerKey:String = <CONSUMER_KEY>;
var consumerSecret:String = <CONSUMER_SECRET>;
//encode key and secret according to twitter's website
var bearerTokenCredentials = Base64.encode(consumerKey + ':' + consumerSecret);
//setup my request variables, according to twitters dev info, use client_credentials for grant_type
var requestVars:URLVariables = new URLVariables();
requestVars.grant_type = 'client_credentials';
//according to twitter, the url to use for application-only authenticaton
var url:String = 'https://api.twitter.com/oauth2/token';
//setup a URLRequest object with the proper headers, according to twitter, need the Authorization header to be 'Basic <encoded key/secret>' and the proper Content-Type header
var request:URLRequest = new URLRequest(url);
request.requestHeaders = [new URLRequestHeader('Authorization', 'Basic ' + bearerTokenCredentials),
new URLRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')];
request.method = URLRequestMethod.POST;
request.data = requestVars;
//send the request to authenticate
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, onBearerTokenRequest);
urlLoader.load(request);
function onBearerTokenRequest(e:Event):void
{
trace('onRequestComplete');
//this works and i get a token
bearerToken = JSON.decode(e.currentTarget.data).access_token;
//HERE IS WHERE I CAN'T FIGURE OUT WHAT'S WRONG
var url:String = 'https://api.twitter.com/1.1/statuses/user_timeline.json'
var urlVariables = new URLVariables();
urlVariables.screen_name = 'rivercitygraphx';
urlVariables.count = 2;
var request:URLRequest = new URLRequest(url);
request.method = "GET";
request.requestHeaders = [new URLRequestHeader('Authorization', 'Bearer ' + bearerToken)];
request.data = urlVariables;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, onTimelineRequestComplete);
urlLoader.load(request);
}
function onTimelineRequestComplete(e:Event):void
{
trace('onTimelineRequestComplete');
}
我正确地获得了令牌(好吧我假设这样,因为我得到一个长串)。
但是当我尝试为用户时间线发出请求时,我收到ioError错误,打开了网址&#39; https://api.twitter.com/1.1/statuses/user_timeline.json?screen%5Fname=kamcknig&count=2&#39;这让我觉得网址格式不正确,但根据我看到的每一个,看起来都是正确的。
此外,我现在只是在Flash IDE中测试它。
任何人都可以帮忙吗?
此后我在Chrome中使用了POSTMAN扩展并输入了url,以及我收到的持有令牌和POSTMAN中的请求的Authorization标头!
所以我唯一能想到的就是Flash IDE。任何人都有任何想法,为什么这可能或甚至可能实际上是问题?
答案 0 :(得分:0)
在我的所有研究之后,看起来这是不可能的。
我找到了一个使用套接字连接的库,它可以做我想要的,但文件大小太大了。 AS3中的Socket类不是安全套接字,因此我无法使用它。并且SecureSocket类不能使用,因为我仅限于Flash Player 10及更早版本。
就我而言,这是不可能的。