【问题标题】:Invalid parameter value for redirect_uri: Invalid scheme: &lt;http:redirect_uri 的参数值无效:无效方案:<http:
【发布时间】:2015-07-31 10:36:42
【问题描述】:

晚上好 - 我正在使用名为“Tutoriel PHP - Importer des contacts Google”的以下 youtube 教程来尝试导入 google 联系人 https://www.youtube.com/watch?v=ysNVe0TaVFs

当我单击链接以导入谷歌联系人时,而不是请求许可并获取联系人并将其显示在屏幕上,出现此问题 - 我收到以下错误:

错误:invalid_request

redirect_uri 的参数值无效:无效方案:http://chi.fis.com/mut_folder/index.php

请告诉我该怎么做才能修复错误。谢谢。

这是我的代码:

<?php 
error_reporting(E_ALL);
ini_set("display_errors", 1);

session_start(); ?>
<!DOCTYPE html>
<html class="no-js" lang="en"/>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Google Contacts API</title>
</head>

<body>
<h2>Google Contacts API v3.0</h2>
<?php
require_once 'lib/google-api-client/autoload.php';
require 'lib/google-api-client/Config.php';
require 'lib/google-api-client/Google_Client.php';

$client_id = '<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbb.cccccccccccc.com>';
$client_secret = '<jfjdkfj3334FdsfJJF9999JK>';
$redirect_uri = '<http://ccccccccccccccccccc.com/rddddddddddd/index.php>';

$client = new Google_Client();
$client -> setApplicationName('contact');
$client -> setClientid($client_id);
$client -> setClientSecret($client_secret);
$client -> setScopes('https://www.google.com/m8/feeds');
$client -> setRedirectUri($redirect_uri);
$client -> setAccessType('online');

if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: ' . $redirect_uri);
}

if(!isset($_SESSION['token']))
{
    $url = $client->createAuthUrl();
    echo '<a href="' . $url . '">Import Google Contacts</a>';
}else{
        $client->setAccessToken($_SESSION['token']);
        $token = json_decode($_SESSION['token']);
        $token->access_token;
        $curl = curl_init("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=50&access_token=" . $token->access_token);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        $contacts_json = curl_exec($curl);
        curl_close($curl);
        $contacts = json_decode($contacts_json, true);
        $return = array();
        foreach($contacts['feed']['entry'] as $contact){
            $return[] = array(
            'name' => $contact['title']['$t'],
            'email' => isset($contact['gd$email'][0]['address']) ? $contact['gd$email'][0]['address'] : false,
            'phone' => isset($contact['gd$phoneNumber'][0]['$t']) ? $contact['gd$phoneNumber'][0]['$t'] :false,
            );
        }
        var_dump($return);
    }       
?>

</body>
</html>

【问题讨论】:

  • 你不应该用&lt;&gt;包装你的变量
  • 谢谢 - 它解决了部分问题 - abraham

标签: php html oauth-2.0 google-plus google-oauth


【解决方案1】:

您传递给 setRedirectUri 的 URL 中有无效字符。

替换:

$redirect_uri = '<http://ccccccccccccccccccc.com/rddddddddddd/index.php>';

$redirect_uri = 'http://ccccccccccccccccccc.com/rddddddddddd/index.php';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 2017-08-27
    • 2014-09-16
    • 2021-04-03
    • 2018-01-03
    • 1970-01-01
    相关资源
    最近更新 更多