ユーザーが「Instagramでサインイン」ボタンをクリックしてInstagramアプリを承認するWordPressのプラグインに取り組んでいます。承認後、プラグインは基本的にユーザーから最新の Instagram の写真を取得し、ウィジェットを介して表示します。
私のプラグインがどのように機能するかのステップバイステップは次のとおりです。
- ユーザーが WordPress 設定ページで [Instagram にサインイン] をクリックします。
- ユーザーは Instagram の認証画面 (ログイン画面) に移動します。
- ユーザーはアプリを正常に認証して承認します。
- Instagram はユーザーを私のRedirect URIにリダイレクトします。
- ファイル「instagram-api-redirect.php」は、「code」パラメーターと「return_uri」パラメーターの両方を取得します。「アクセストークン」を要求するために「コード」が使用される場所。
- 「アクセス トークン」とともに WordPress 設定ページにリダイレクトされます。
- プラグインは、リクエストの認証に使用する「アクセス トークン」をデータベースに保存します。
私が問題を抱えているのは、ステップ 5 で「リダイレクト URI が元のリダイレクト URI と一致しません」というエラー メッセージが表示されることです。リダイレクト URIから「return_uri」クエリ パラメータを削除すると、問題なく動作します。
いくつかの詳細が役立つ場合があります。
アプリからのリダイレクト URIは次のとおりです。
http:// mysite.com/plugins/pulp_instagram/instagram-api-redirect.php
Instagram の"/authorize"に送信するリダイレクト URIは次のとおりです。
http://mysite.com/plugins/pulp_instagram/instagram-api-redirect.php?return_uri=http://localhost/instagram-app
Instagram の"/authorize"に送信する完全な認証 URL は次のとおりです。
https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=http://mysite.com/plugins/pulp_instagram/instagram-api-redirect.php?return_uri=http://localhost/instagram -app&response_type=コード
URL 応答は次のとおりです。
http://mysite.com/plugins/pulp_instagram/instagram-api-redirect.php?return_uri=http://localhost/instagram-app&code=557d15dacd0d40459edf70aa159476de
これは、「instagram-api-redirect.php」ファイルの完全なコードです。
<?php
// the redirect uri
$return_uri = $_GET['return_uri'];
require 'instagram.class.php';
// Initialize class
$instagram = new Instagram(array(
'apiKey' => 'CLIENT-ID',
'apiSecret' => 'CLIENT-SECRET',
'apiCallback' => 'http://mysite.com/plugins/pulp_instagram/instagram-api-redirect.php'
));
// Receive OAuth code parameter
$code = $_GET['code'];
// Check whether the user has granted access
if (true === isset($code)) {
// Receive OAuth token object
$data = $instagram->getOAuthToken($code);
print_r($data);
} else {
// Check whether an error occurred
if (true === isset($_GET['error'])) {
echo 'An error occurred: '.$_GET['error_description'];
}
}
?>
また、 cosenaryの「Instagram PHP API」クラス (instagram.class.php) を使用しています。
前もって感謝します!