1) Project/src/ OAuthのようなディレクトリを作成します
2) クラスをそのディレクトリ内の個別のファイルに配置します。
namespace OAuth;
3)すべての OAuth クラスの先頭に追加します。
4) 例外クラスにバックスラッシュを追加 (または追加use Exception;
):
class OAuthException extends \Exception
5) クラス名にアンダースコアを使用しないようにします ( Laravel 4のLaravel-Oauth2 の問題、名前空間とクラス名のアンダースコア):
abstract class OAuthSignatureMethodRSASHA1 extends OAuthSignatureMethod
class OAuthSignatureMethodPLAINTEXT extends OAuthSignatureMethod
class OAuthSignatureMethodHMACSHA1 extends OAuthSignatureMethod
6) OAuthUtil の array_map 呼び出しを修正します。
return array_map(array('OAuth\OAuthUtil', 'urlencode_rfc3986'), $input);
7) そして最後にそれを使用します:
<?php
namespace My\PlaygroundBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use OAuth\OAuthConsumer;
use OAuth\OAuthRequest;
use OAuth\OAuthSignatureMethodHMACSHA1;
use OAuth\OAuthUtil;
class DefaultController extends Controller
{
/**
* @Route("/")
* @Template()
*/
public function indexAction()
{
$cc_key = "your consumer key here";
$cc_secret = "your consumer secret here";
$url = "http://yboss.yahooapis.com/ysearch/news,web,images";
$args = array();
$args["q"] = "yahoo";
$args["format"] = "json";
$consumer = new OAuthConsumer($cc_key, $cc_secret);
$request = OAuthRequest::from_consumer_and_token($consumer, NULL,"GET", $url, $args);
$request->sign_request(new OAuthSignatureMethodHMACSHA1(), $consumer, NULL);
$url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));
$ch = curl_init();
$headers = array($request->to_header());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$rsp = curl_exec($ch);
$results = json_decode($rsp);
return array(
'results' => $results
);
}
}
これらは私が従った手順であり、うまくいきました。ここからクラスを取得できます: https://github.com/coma/OAuthSOSample