php - $_GET ['code' 的来源] 以获取 youtube api 凭据的刷新 token

标签 php api curl get refresh

我是 php 的学习者,在尝试生成刷新 token 之后,我必须使用 youtube api 凭据,我找到了这段代码,但我不知道 $code 在哪里从。

谁能帮我找出这个 $_GET['code'] 在下面的代码中来自哪里,这是我在堆栈溢出中的第一个问题。如有错误请忽略。

 if(isset($_GET['code'])) {

     $code = $_GET['code'];

    $url = 'https://accounts.google.com/o/oauth2/token';

    $params = array(
        "code" => $code,

        "client_id" => "client_id",
        "client_secret" => "client_secret",
        "redirect_uri" => "redirect_uri",
        "grant_type" => "authorization_code"
    );
    $curl = curl_init($url);

    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  

    $json_response = curl_exec($curl);
    curl_close($curl);
    $authObj = json_decode($json_response);

    "access_token: " . $authObj->access_token;
    "token_type: " . $authObj->token_type;
    "expires_in: " . $authObj->expires_in;
    "refresh_token: " . $authObj->refresh_token;

 }

最佳答案

通常你的网址是

    http://example.com/yourpage.php?code=abbcd

这种类型的 url 在这个查询字符串中被称为查询字符串有 2 个变量 注意 ?after 你只是给你的数据分配一个像上面这样的变量 您可以使用&例如添加更多数据。 &secondcode=abcasdda 所以你的新网址将是

 http://example.com/yourpage.php?code=abbcd&secondcode=abcasdda

所以

     $code = $_GET['code'];

        echo $code  

///OUTPUT  :  abbcd

这是获取变量的方式

关于php - $_GET ['code' 的来源] 以获取 youtube api 凭据的刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46925578/

相关文章:

php - 如何在 PHP 中使用正则表达式匹配固定数量的数字?

php - 从 PHP 上的 JSON 数据中选择一个数组

php - 使用 PHP 和 CURL 创建新的 etherpad

javascript - 如何使用 PHP/Curl 模拟 javascript 生成的下载请求

php.ini 文件不起作用?

php - 为什么 mysql INSERT 行为错误?

php - 获取多维数组

ruby-on-rails - 有什么可以解释 Rails 的 API 文档吗?

python - 拜比特 API : is there a way to place Take Profit & Stop Loss orders after a opening a position?

laravel - 在 Laravel 5.4 中保存模型后出现 cURL 错误 3 : <url> malformed (see http://curl. haxx.se/libcurl/c/libcurl-errors.html) 错误