我是 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/