我在使用OAuthorization时遇到问题,我有一个请求PHP脚本的Flash播放器应用程序。 PHP总是返回:
{"status":false,"message":"Invalid Signature"}
我尝试了两个不同的库:
https://github.com/yahoo/yos-social-as3
https://github.com/iotashan/oauth-as3
我不知道再试一次,有人可以帮我吗?
生成错误网址的as3脚本:
import com.yahoo.oauth.OAuthRequest;
import com.yahoo.oauth.OAuthConsumer;
import com.yahoo.oauth.OAuthSignatureMethod_HMAC_SHA1;
import com.yahoo.oauth.IOAuthSignatureMethod;
import com.yahoo.oauth.OAuthToken;
import com.yahoo.oauth.OAuthUtil;
var signature:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
var consumer:OAuthConsumer = new OAuthConsumer("myKey", "mySecret");
var oauthRequest:OAuthRequest =
new OAuthRequest(
"GET",
"http://mySite.com/index.php",
null,
consumer,
null
);
var request:URLRequest = new URLRequest(oauthRequest.buildRequest(signature));
var loader:URLLoader = new URLLoader;
loader.addEventListener(Event.COMPLETE, getComplete);
loader.load(request);
function getComplete(event:Event):void
{
trace("data", URLLoader(event.currentTarget).data);
}
我在PHP脚本中做了一个生成正确URL的示例:
<?php
// include oath
require_once('OAuth/OAuth.php');
if ($mode == 'generate')
{
$consumer = new OAuthConsumer(OAUTHKEY, OAUTHSECRET);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1;
// call this file
$api_endpoint = $_GET['url'];
//use oauth lib to sign request
$req = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', $api_endpoint, $parameters);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$req->sign_request($sig_method, $consumer, null); //note: double entry of token
echo $req->to_url();
exit;
}
这是PHP脚本生成的url,这项工作:
http://mySite.com/index.php?
oauth_consumer_key=myKey&
oauth_nonce=20de438daf761115018b3d6f26456a6e&
oauth_signature=JpWrfU77Pl%2FfFoa%2BhVy8agq9I5Q%3D&
oauth_signature_method=HMAC-SHA1&
oauth_timestamp=1347583047&
oauth_version=1.0
这是AS3脚本生成的url,这不起作用:
http://mySite.com/index.php?
oauth_consumer_key=myKey&
oauth_nonce=b8808c76e9aaa264964aefabb22bdc55&
oauth_signature=jZ31R4C0Ybj1dluIjy6wKCtN7D4%3D&
oauth_signature_method=HMAC-SHA1&
oauth_timestamp=1348705359&
oauth_version=1.0
答案 0 :(得分:0)
解决了:)
感谢PeeHaa告诉我使用的是2.0版库,现在我正在使用iotashan lib,即版本1.0,它现在正在运行:)
import org.iotashan.oauth.IOAuthSignatureMethod;
import org.iotashan.oauth.OAuthConsumer;
import org.iotashan.oauth.OAuthRequest;
import org.iotashan.oauth.OAuthSignatureMethod_HMAC_SHA1;
import org.iotashan.oauth.OAuthToken;
import org.iotashan.utils.OAuthUtil;
import org.iotashan.utils.URLEncoding;
var signature:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
var consumer:OAuthConsumer = new OAuthConsumer("myKey", "mySecret");
var oauthRequest:OAuthRequest =
new OAuthRequest(
OAuthRequest.HTTP_METHOD_GET,
"http://mySite.com/index.php",
null,
consumer,
null
);
var request:URLRequest = new URLRequest(oauthRequest.buildRequest(signature, OAuthRequest.RESULT_TYPE_URL_STRING));
// Creating URLLoader to invoke Google service
var loader:URLLoader = new URLLoader;
loader.addEventListener(Event.COMPLETE, getComplete);
loader.load(request);
trace("request", request.url);
function getComplete(event:Event):void
{
trace("data", URLLoader(event.currentTarget).data);
}