使用 .访问 Google API OAuth2Service Account
时出现问题google-api-php-client
。我惊讶地发现这部分代码来自Google Dev 中设置的 JWT 声明示例,JWT Claim set
当由于某种原因JWT Header
通过 true 时返回错误,这让我感觉像 UTF-8 序列化并json_encode()
在此处创建错误。
$JWT_Header = array(
"alg" => "RS256",
"typ" => "JWT"
);
$JWT_Body = array(
"iss" => "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com",
"scope" => "https://www.googleapis.com/auth/prediction",
"aud" => "https://accounts.google.com/o/oauth2/token",
"exp" => 1328554385,
"iat" => 1328550785
);
$segments = array(
rtrim(strtr(base64_encode(json_encode($JWT_Header)), '+/', '-_'), '='),
rtrim(strtr(base64_encode(json_encode($JWT_Body)), '+/', '-_'), '=')
);
//echo '<pre>'; print_r($segments); echo '</pre>';
不同于Google Dev: Encoding the JWT Claim Set example of output中描述的内容
/*
Output:
JWT header:
Google Dev eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.
My output eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.
JWT Claim set:
Google Dev eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ.
My output eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOlwvXC93d3cuZ29vZ2xlYXBpcy5jb21cL2F1dGhcL3ByZWRpY3Rpb24iLCJhdWQiOiJodHRwczpcL1wvYWNjb3VudHMuZ29vZ2xlLmNvbVwvb1wvb2F1dGgyXC90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ.
*/
有什么建议么?