Comments (1)
Hi @wenshan, thanks for raising this issue. The "Failed to connect" error (code 28) usually indicates a network-level problem rather than an issue with the code (and thus this library) itself. I've tried reproducing it with curl as well as using PHP curl and didn't face any issue.
Code
<?php
use Firebase\JWT\JWT;
require_once __DIR__ . '/../vendor/autoload.php';
$key = getSignedJwtClaim();
sendCurlRequest($key);
function getSignedJwtClaim()
{
$jwtClaims = [
"iss" => getenv('SERVICE_ACCOUNT_EMAIL'),
"scope" => "https://www.googleapis.com/auth/devstorage.read_only",
"aud" => "https://oauth2.googleapis.com/token",
"exp" => time() + 3600,
"iat" => time()
];
$key = json_decode(file_get_contents(getenv('GOOGLE_APPLICATION_CREDENTIALS')), true);
return JWT::encode(
$jwtClaims,
$key['private_key'],
'RS256'
);
}
function sendCurlRequest($key) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://oauth2.googleapis.com/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded',
]);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=' . $key
);
$response = curl_exec($ch);
$response = json_decode($response, true);
echo "Access token => " . $response['access_token'] . PHP_EOL;
curl_close($ch);
}
You can try adding -v
flag to you curl command to get more verbose output and get some clue as to why it's happening on your system. It's very helpful that you've confirmed it works with Postman. This reinforces the idea that the issue likely lies in the network configuration on the machine where cURL is running.
As there isn't anything actionable in this library, hence closing this issue.
from google-api-php-client.
Related Issues (20)
- Status run HOT 2
- Problem retrieving domain user list HOT 1
- Feat. request: timeout for default http client
- Uncaught Error: Class 'Google_Service_Customsearch' HOT 2
- insert product using google-api-php-client HOT 1
- Changing OAuth scope giving invalid credentials error for existing users when appending rows in google sheet.
- PAGINATION - Next page token is always null ? HOT 1
- Issue with Namespacing Google Libraries in WordPress Plugin HOT 2
- Issue with Namespacing Google Libraries in WordPress Plugin HOT 1
- [reasonPhrase:GuzzleHttp\Psr7\Response:private] => Forbidden HOT 3
- Dependency phpseclib/phpseclib has a security update HOT 1
- Support for "forHandle" parameter in youtube->channels->list request HOT 3
- Extending Google Analytics APIs: Best Practices and Customization Techniques HOT 1
- How to set "enable_granular_consent" parameter on Client.php? HOT 4
- Hey, I’ve been working with Swoole and I think there’s an issue when the application runs in a resident memory environment HOT 1
- Oath without json file HOT 1
- Uncaught TypeError: Argument must be an instance of RenderAccountIssuesRequestPayload HOT 1
- Custom Namespace issue on google analytics-admin and analytics-data php api. HOT 2
- Google does not return refresh token and the token does not refresh automatically HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-api-php-client.