2

我目前被困在尝试使用 PHP 使用 2 腿 oAuth 请求向服务的 api 发出请求。

我正在使用此处找到的 PHP 库:http ://code.google.com/p/oauth-php/并且似乎绝对没有任何在线文档可以使用此库进行 2 条腿请求。

所以目前从服务中我有以下详细信息:

  • $consumer_key -需要是一个空字符串
  • $consumer_secret -需要是一个空字符串
  • $access_token -我的登录名
  • $access_token_secret -您生成的应用程序令牌

我希望能够提出以下请求:

http://foo.com/api/test/whoami

测试身份验证是否正常工作,以便我可以使用 api 的其余部分。

有人对如何使用该 php 库来实现这一点有任何指示吗?还是有更好的方法来进行这样的简单 2 腿呼叫?

帮助!?:)

4

2 回答 2

1

这个小例子可能会有所帮助http://developer.yahoo.com/blogs/ydn/posts/2010/04/a_twolegged_oauth_serverclient_example/

于 2010-09-02T18:43:40.187 回答
0

您只需要消费者密钥和消费者秘密来发出授权的 2-legged oauth 请求。

下载OAuthConsumer. OAuthException(将第 6-8 行注释掉)

代码示例:

require_once 'OAuth.php';

$signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
$consumerKey = 'abc';
$consumerSecret = 'def';
$httpMethod = 'GET';
$url = 'http://path/to/endpoint';
$requestFields = array();

$oauthConsumer = new OAuthConsumer($consumerKey, $consumerSecret, NULL);
$oauthRequest = OAuthRequest::from_consumer_and_token($oauthConsumer, NULL, $httpMethod, $url, $requestFields);
$oauthRequest->sign_request($signatureMethod, $oauthConsumer, NULL);
于 2015-02-16T13:00:37.123 回答