0

我在使用 OAuthorization 时遇到问题,我有一个请求 PHP 脚本的 Flash 播放器应用程序。PHP 总是返回:

{"status":false,"message":"Invalid Signature"}

我尝试了两个不同的库:

https://github.com/yahoo/yos-social-as3
https://github.com/iotashan/oauth-as3

我不知道再尝试什么,有人可以帮我吗?

生成错误 URL 的 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
4

1 回答 1

0

解决了 :)

感谢 PeeHaa 告诉我使用的是 2.0 版库,现在我正在使用 iotashan 库,即 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);
}
于 2012-09-27T01:40:13.200 回答