我在使用Action Script 3.0 OAuth将其与Twitter集成时遇到问题。
对于那些使用Flash开发的人来说,ActionScript可能会知道这两个库:
High level AS3/Flex library for OAuth
我在测试闪光灯时遇到问题,这是我得到的错误:
/Users/Testing.as, Line 20 1180: Call to a possibly undefined method OAUth.
/Users/Testing.as, Line 20 1188: Illegal assignment to class IOAuth.
/Users/Testing.as, Line 22 1120: Access of undefined property oauth.
/Users/Testing.as, Line 34 1180: Call to a possibly undefined method OAUth.
我刚从第一个链接页面复制了代码并过去了。一切似乎都很好但我不知道是什么问题。还是初学者。我也正确导入了所有库。
包{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import org.flaircode.oauth.*;
import org.iotashan.oauth.*;
public class Testing extends MovieClip {
private var consumerKey:String = "KEYKEYHERE"; // hidden for privacy purposes
private var consumerSecret:String = "KYEKEYKEYHERE"; // hidden for privacy purposes
public function Testing() {
// constructor code
ini();
}
public function ini():void{
btn.addEventListener(MouseEvent.CLICK, whenClicked);
}
function whenClicked():void{
// create OAuth
oauth:IOAuth = new OAUth(consumerKey, consumerSecret);
// get request token
var loader:URLLoader = oauth.getRequestToken("http://twitter.com/oauth/request_token");
loader.addEventListener(Event.COMPLETE, requestTokenHandler);
}
function requestTokenHandler(e:Event):void
{
requestToken = OAuthUtil.getTokenFromResponse(e.currentTarget.data as String);
var request:URLRequest = oauth.getAuthorizeRequest("http://twitter.com/oauth/authorize", requestToken.key);
// opens website where user has to login on Twitter and gets 6 digit pin code
navigateToURL(request, "_blank");
}
function getAccessToken(pin:int):void
{
var loader:URLLoader = oauth.getAccessToken("http://twitter.com/oauth/access_token", requestToken, {oauth_verifier:pin});
loader.addEventListener(Event.COMPLETE, accessTokenHandler);
}
function accessTokenHandler(e:Event):void
{
accessToken = OAuthUtil.getTokenFromResponse(e.currentTarget.data as String);
// TODO store accessToken.key and accessToken.secret in EncryptedLocalStorage for all further requests
}
}
}
答案 0 :(得分:0)
尝试更改以下行:
oauth:IOAuth = new OAUth(consumerKey, consumerSecret);
为:
var oauth:OAuth = new OAUth(consumerKey, consumerSecret);
我发现vars存在同样的问题:'requestToken'和'accessToken'。你需要通过在它们前面放一个'var'来将它们声明为变量;即,“var myVar:VarType”。此外,如果您在创建它们的函数内声明这些变量,那么它们只能在这些函数中可见。如果您希望它们对整个类可见,请将它们声明为类变量,就像您使用键一样:即“private var requestToken:String;”