大丈夫、私はこの1つに困っています。Tumblr OAuth PHPのOAuthクラスを使用して
私は最近、ここにPHPのOAuthライブラリをダウンロードしてインストール:http://us3.php.net/manual/en/book.oauth.php
がこれを使用して、私は自分のTumblrのアカウントに接続してポストを作成しようとするいくつかのテストコードを作成しました。
RequestTokenとAuthorizeを取得できました。私は、実際の要求を行うとき、しかし、私はエラーを取得する:
Invalid auth/bad request (got a 404, expected HTTP/1.1 20X or a redirect)
マイリクエストURLはhttp://api.tumblr.com/v2/blog/account/postの正しい形式です。私はPOSTリクエストをしています。それはここでは404
を返している理由だから私はわからない私のコードです:
<?php
$req_url = 'http://www.tumblr.com/oauth/request_token';
$authurl = 'http://www.tumblr.com/oauth/authorize';
$acc_url = 'http://www.tumblr.com/oauth/access_token';
$conskey = '123';
$conssec = '456';
session_start();
// In state=1 the next request should include an oauth_token.
// If it doesn't go back to 0
if(!isset($_GET['oauth_token']) && $_SESSION['state']==1) $_SESSION['state'] = 0;
try {
$oauth = new OAuth($conskey,$conssec);
$oauth->enableDebug();
if(!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$request_token_info = $oauth->getRequestToken($req_url, 'http://www.domain.com/oauth.php');
$_SESSION['secret'] = $request_token_info['oauth_token_secret'];
$_SESSION['state'] = 1;
//Make authorize request with oauth_token
header('Location: '.$authurl.'?oauth_token='.$request_token_info['oauth_token']);
exit;
} else if($_SESSION['state']==1) {
//Callback code
$oauth->setToken($_GET['oauth_token'],$_SESSION['secret']);
$access_token_info = $oauth->getAccessToken($acc_url);
$_SESSION['state'] = 2;
$_SESSION['token'] = $access_token_info['oauth_token'];
$_SESSION['secret'] = $access_token_info['oauth_token_secret'];
}
//Make tumblr post request
$oauth->setToken($_SESSION['token'],$_SESSION['secret']);
$oauth->fetch("http://api.tumblr.com/v2/blog/account/post", null, OAUTH_HTTP_METHOD_POST, array('type'=>'text', 'body'=>'this is a test')); //error happens here
$json = json_decode($oauth->getLastResponse());
print_r($json);
} catch(OAuthException $E) {
print_r($E);
}
?>
任意のヒントを大幅に私は答えを見つけた
もすることを忘れないでください動作するようにこれを得ることにチュートリアルを書いた私の例への変換で
:正しい順序はこれです許可されたフェッチ呼び出しの前にsetTokenメソッドを呼び出します。 – JacopKane