Jan*_*tia 5 php wordpress oauth instagram
我正在为WordPress开发插件,其中用户单击“在Instagram上登录”按钮以授权我的Instagram应用。授权后,该插件基本上只会从用户那里获取最新的Instagram照片,并通过小部件进行显示。
这是我的插件如何工作的分步说明:
我遇到的问题是,我在步骤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'];
}
}
?>
Run Code Online (Sandbox Code Playgroud)
另外,我正在使用来自cosenary的“ Instagram PHP API”类(instagram.class.php)。
提前致谢!
| 归档时间: |
|
| 查看次数: |
2534 次 |
| 最近记录: |