pulkitjalan / google-apiclient Goto Github PK
View Code? Open in Web Editor NEWGoogle api php client wrapper with Cloud Platform and Laravel support
License: MIT License
Google api php client wrapper with Cloud Platform and Laravel support
License: MIT License
Add @mixin docblock to Facade to make usability more comfortable
I'm an Google Admin of my own organization. Google API keys and API access all setup and ready to go. My goal is to manage Gmail accounts without OAuth auth, so I'm forced to use the Google Service Account. To get all users - as an example - I had to create a workaround.
To reproduce:
Change the scopes in your config/google.php file:
'scopes' => [
'https://www.googleapis.com/auth/admin.directory.user'
],
Add these values in your .env file:
GOOGLE_SERVICE_ENABLED=true
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION='/path/to/your/file.json'
Now try to gain access to your users:
Route::get('no-users', function()
{
$service = Google::make('directory'); // according to readme
$results = $service->users->listUsers(); // call to get a list of users
dump($results); // Google_Service_Exception 400 Bad Request
});
To get it working, I ended up using this...
Route::get('users', function()
{
$client = new \PulkitJalan\Google\Client(config('google'), '[email protected]');
$service = new Google_Service_Directory($client->getClient());
$optParams = array(
'domain' => 'mydomain.com', //required
);
$results = $service->users->listUsers($optParams);
dump($results->users);
});
Isn't there a better way to handle this?
Hello, hope somebody can help me, Im trying to install. the package in "laravel/framework": "^8.40", but Im getting this error
Problem 1
pulkitjalan/google-apiclient[3.1.0, ..., 3.1.4] require illuminate/support ~5 -> found illuminate/support[v5.0.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.
Root composer.json requires pulkitjalan/google-apiclient ^3.1 -> satisfiable by pulkitjalan/google-apiclient[3.1.0, ..., 3.1.4].
Are there any plans on Laravel 11 support?
Hi there,
I want to use the Google Play Developer API with a service user. I've got the error;
{ "error": "invalid_scope", "error_description": "Empty or missing scope not allowed." }
What to do?
Is there an easier way to pass a user email to the Client other than extending it in a service provider?
// Override pulkitjalan/google-apiclient
$this->app->extend('PulkitJalan\Google\Client', function ($command, $app) {
$config = $app['config']['google'];
$user = '[email protected]';
return new Client($config, $user);
});
Thanks!
-reasonPhrase: "No Content"
-statusCode: 204
How to add monolog handlers through config?
I can't get my head around what I'm doing wrong here. I'm trying to connect using Service Account.
GOOGLE_APPLICATION_NAME=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT=
GOOGLE_DEVELOPER_KEY=
GOOGLE_SERVICE_ENABLED=true
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=/resources/google/service-account.json
I get the error:
InvalidArgumentException
file does not exist
What am I doing wrong?
(I have tried different variations of the path)
What I should use instead of authenticate method ??
This is my code:
$client = new \PulkitJalan\Google\Client(['client_id' => 'YOUR_CLIENT_ID', 'client_secret' => 'YOUR_SECRET', 'redirect_uri' => 'YOUR_REDIRECT_URI', 'developer_key' => 'YOUR_KEY']);
$google = $client->getClient();
$google->authenticate($token);
$access_token = $client->getAccessToken()["access_token"];
//and now here you go
$user = Socialite::driver('google')->userFromToken($access_token);
hello, thanks a lot for your work, i have a question, how can I pass another array config (not config/google.php) to setClient?
- Conclusion: don't install laravel/framework v9.0.0-beta.1 (conflict analysis result) - pulkitjalan/google-apiclient dev-master requires illuminate/support ^5.8|^6.0|^7.0|^8.0 -> satisfiable by illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev].
I'm struggling to understand the correct way to write the path to the service account .json file.
Help would be appreciated.
Just wanted to know where to start the google API drive created by you. I mean do you have any demo? I setup credentials already. In laravel controller I added something like this:
$client = Google::getClient();
$service = new Google_Service_Drive($client);
got an error Class 'App\Http\Controllers\Google_Service_Drive' not found. I just wanted to use the google drive api all through way in my application. GET files details and links.
Hi,
I need to get all the contacts associated with an email. Do you have any examples to do this?
Thanks.
There is a big problem with the fact that you're returning a Singleton from the GoogleServiceProvider.
Since there is just one instance of the PulkitJalan\Google\Client
class, there are a lots of problems when I call the getClient() method, which returns always the same instance as well, and then I try to set up different Auth keys with the setAccessToken()
method.
What happens is that if I have 2 queue jobs running in the background almost at the same time, then the Auth tokens are not saved separately, but one overrides the other, causing of course tons of problem and mixing the user's account!
Instead of using $this->app->singleton()
you should probably use $this->app->make()
so that it's easier to instantiate a new instance every time.
Thanks!
[2017-01-27 19:34:45] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Illuminate\Foundation\Application::share() in vendor/pulkitjalan/google-apiclient/src/GoogleServiceProvider.php:39
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Foundation/Application.php(568): PulkitJalan\Google\GoogleServiceProvider->register()
#1 vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(74): Illuminate\Foundation\Application->register(Object(PulkitJalan\Google\GoogleServiceProvider))
#2 vendor/laravel/framework/src/Illuminate/Foundation/Application.php(543): Illuminate\Foundation\ProviderRepository->load(Array)
#3 vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\Foundation\Application->registerConfiguredProviders()
#4 vendor/laravel/framework/src/Illuminate/Foundation/Application.php(208): Illuminate\Foundation\Bootstrap\RegisterProviders->bootstrap(Object(Illuminate\Foundation\Application))
#5 vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(270): Illuminate\Foundation\Application->bootstrapWith(Array)
#6 vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(115): Illuminate\Foundation\Console\Kernel->bootstrap()
#7 artisan(34): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 {main}
Problem 1
- Root composer.json requires pulkitjalan/google-apiclient ^5.0 -> satisfiable by pulkitjalan/google-apiclient[5.0.0].
- pulkitjalan/google-apiclient 5.0.0 requires illuminate/support ^6.0|^7.0|^8.0 -> found illuminate/support[v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but it conflicts with your root composer.json require (^9.0).
Problem 2
- pulkitjalan/google-apiclient 5.0.0 requires illuminate/support ^6.0|^7.0|^8.0 -> found illuminate/support[v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but it conflicts with your root composer.json require (^9.0).
- revolution/laravel-google-sheets 5.8.0 requires pulkitjalan/google-apiclient ^4.1||^5.0 -> satisfiable by pulkitjalan/google-apiclient[5.0.0].
- Root composer.json requires revolution/laravel-google-sheets ^5.8 -> satisfiable by revolution/laravel-google-sheets[5.8.0].
Hey,
Looking to install this on Laravel 8 however no support yet. Would it be as simple as a pull request bumping the dependency number?
I wish a knew a little more to help out.
It seems approval_prompt has deprecated long time ago.
Can we replace the approval_prompt to prompt?
From what I can tell, Google Cloud Vision is included in the API services. I've got everything setup but when I try to run a basic test (using an example from the Google Cloud Client PHP Library for Google Vision), I get an undefined method error. Here's my code:
$vision = Google::make('vision');
$familyPhotoResource = fopen('images/1e5a7f132d42540feae50b187233676b/592e338a86913-071616-098-1700x1152.jpg', 'r');
$image = $vision->image($familyPhotoResource, ['FACE_DETECTION']);
$result = $vision->annotate($image);
return $result;
I'm adding use Google at the top of my controller and I've tried both $vision = Google::make('vision'); and $vision = \Google::make('vision');
When I run the function it returns "Call to undefined method Google_Service_Vision::image()"
It references this line for the error:
$image = $vision->image($familyPhotoResource, ['FACE_DETECTION']);
Any ideas? Any help would be greatly appreciated.
Any plan to support php 8?
Thanks!
I am looking to be able to read a user's email in the gmail. Basically watch for any updates in the inbox matching a string e.g. Stock Alerts . I can I use this client? If yes, can you please document an example.
Google Sheets API now uses underscores instead of backslash which causes the package to throw UnknownServiceException error
https://developers.google.com/sheets/api/guides/values#write_multiple_ranges
vendor\pulkitjalan\google-apiclient\src\Client.php
/**
* Getter for the google service.
*
* @param string $service
* @return \Google_Service
*
* @throws \Exception
*/
public function make($service)
{
$service = 'Google\\Service\\'.ucfirst($service);
if (class_exists($service)) {
$class = new \ReflectionClass($service);
return $class->newInstance($this->client);
}
throw new UnknownServiceException($service);
}
Hi, i am getting following error.
Google_Service_SiteVerification_Resource_WebResource::getToken() must be an instance of Google_Service_SiteVerification_SiteVerificationWebResourceGettokenRequest, array given,
There is no method or facade to create Google_Service_SiteVerification_SiteVerificationWebResourceGettokenRequest in your library, we need to create instance exclusively for passing it. can't you do out of the box.
How can i get user active devices ?
"Error calling POST https://www.googleapis.com/oauth2/v2/tokeninfo: (400) {\n "error_description": "Invalid Value"\n}\n"
I'm getting this error when using directory SDK
it seems like i need to set sub somehow
i know that i can set sub Google::getClient() with a second parameter
but how can i set sub when i need to get a service?
$directory = Google::make('directory');
is there any way to set sub in above command?
I keep getting the following error:
Error calling GET https://www.googleapis.com/gmail/v1/users/me/messages: (400) Bad Request
with the following code:
$gmail = \Google::make('gmail');
$results = $gmail->users_messages->listUsersMessages('me');
As far as I can tell I have set up the credentials correctly yet, its not working. Any advise?
I am unable to create a service object which accept constructor params. Please refer following example
$userPermission = new Google_Service_Drive_Permission(array(
'type' => 'user',
'role' => 'writer',
'emailAddress' => '[email protected]'
));
Since the make
method doesn't accept any params other than service name, how can I pass constructor params and set it while creating service object ?
v2 has been out for a while now. It would be nice to see updates to the package to use v2 instead.
I am getting following error:
FatalErrorException in Client.php line 267:
Call to undefined method Google_Auth_ComputeEngine::createAuthUrl()
Please give me some solution for this.
I am using the Google People API to create a new contact in Google Contacts but it is not saved or synced in Google Contacts.
I'm not getting any errors.
Here is the code I am using to create the contact:
$client = new GoogleClient(config('google'));
$googleClient = $client->getClient();
$peopleService = new PeopleService($googleClient);
$newContact = new \Google\Service\PeopleService\Person();
$newContact->setNames([new Google_Service_PeopleService_Name(['givenName' => 'John', 'familyName' => 'Doe'])]);
$newContact->setEmailAddresses([new Google_Service_PeopleService_EmailAddress(['value' => '[email protected]'])]);
$respose = $peopleService->people->createContact($newContact);
dd($respose); // it rerurns respose of person
The $newContact variable contains the newly created contact's resource name. I have also tried requesting a sync for the connection, as follows:
$client = new GoogleClient(config('google'));
$googleClient = $client->getClient();
$peopleService = new PeopleService($googleClient);
$params = [
'personFields' => 'metadata,names,emailAddresses,phoneNumbers',
'pageSize' => 2000,
'requestSyncToken' => true
];
$fullSyncResponse = $peopleService->people_connections->listPeopleConnections('people/me', $params);
while ($fullSyncResponse->getNextPageToken() != null) {
$fullSyncResponse = $peopleService->people_connections->listPeopleConnections('people/me', [
'personFields' => 'metadata,names,emailAddresses,phoneNumbers',
'pageSize' => 2000,
'requestSyncToken' => true,
'pageToken' => $fullSyncResponse->getNextPageToken()
]);
}
// Fetch incremental changes using the sync token returned in the last fullSyncResponse.
// try {
$incrementalSyncResponse = $peopleService->people_connections->listPeopleConnections('people/me', [
'personFields' => 'metadata,names,emailAddresses,phoneNumbers',
'pageSize' => 2000,
'syncToken' => $fullSyncResponse->getNextSyncToken()
]);
if ($incrementalSyncResponse->getConnections() != null)
foreach ($incrementalSyncResponse->getConnections() as $person) {
$this->handlePerson($person);
}
while ($incrementalSyncResponse->getNextPageToken() != null) {
$incrementalSyncResponse = $peopleService->people_connections->listPeopleConnections('people/me', [
'personFields' => 'metadata,names,emailAddresses,phoneNumbers',
'pageToken' => $incrementalSyncResponse->getNextPageToken(),
'pageSize' => 2000,
'syncToken' => $fullSyncResponse->getNextSyncToken()
]);
if ($incrementalSyncResponse->getConnections() != null)
foreach ($incrementalSyncResponse->getConnections() as $person) {
$this->handlePerson($person);
}
}
dd($fullSyncResponse, $incrementalSyncResponse); // it rerurns respose of listPeopleConnections
//
} catch (\Exception $ex) {}
public function handlePerson(PeopleService\Person $person)
{
if ($person->getMetadata()->getDeleted()) {
// Handle deleted person
} else {
// Handle changed person
}
}
However, the contact is still not saved or synced in Google Contacts.
Can anyone please advise on what might be causing this issue, and how I can get the newly created contact to be saved and synced in Google Contacts? Thank you in advance for your help.
I'm getting this error when trying to install the package via Composer:
Problem 1
- Conclusion: don't install phpseclib/phpseclib 2.0.2
- Installation request for tymon/jwt-auth 0.5.* -> satisfiable by tymon/jwt-auth[0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.5.6, 0.5.7, 0.5.8, 0.5.9].
- Installation request for pulkitjalan/google-apiclient 3.* -> satisfiable by pulkitjalan/google-apiclient[3.0.0].
- Conclusion: don't install phpseclib/phpseclib 2.0.1
- pulkitjalan/google-apiclient 3.0.0 requires google/apiclient ^2.0 -> satisfiable by google/apiclient[v2.0.0, v2.0.1].
- google/apiclient v2.0.0 requires phpseclib/phpseclib ~2.0 -> satisfiable by phpseclib/phpseclib[2.0.0, 2.0.1, 2.0.2].
- google/apiclient v2.0.1 requires phpseclib/phpseclib ~2.0 -> satisfiable by phpseclib/phpseclib[2.0.0, 2.0.1, 2.0.2].
- Conclusion: don't install phpseclib/phpseclib 2.0.0|install phpseclib/phpseclib 2.0.1|install phpseclib/phpseclib 2.0.2
My composer.json looks like this:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"filp/whoops": "~1.0",
"tymon/jwt-auth": "0.5.*",
"pulkitjalan/google-apiclient": "3.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"laracasts/generators": "^1.1",
"symfony/dom-crawler": "~3.0",
"symfony/css-selector": "~3.0"
},
Not sure what's wrong here since I was able to install the package with the last version.
I looked through the code and couldn't find the issue.
But when I run php artisan vendor:publish it doesn't publish config/config.php to config_path(google.php)
I'm finding that when I use the Facades with a service account I'm getting incorrect scope errors. Basically this returns a list of books:
$client = new \Google_Client();
$service = new \Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
foreach ($results as $item) {
echo $item['volumeInfo']['title'], "<br /> \n";
}
and this is returning an error
$client = Google::getClient();
$service = Google::make('books');
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
foreach ($results as $item) {
echo $item['volumeInfo']['title'], "<br /> \n";
}
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires pulkitjalan/google-apiclient ^6.0 -> satisfiable by pulkitjalan/google-apiclient[6.0.0].
- pulkitjalan/google-apiclient 6.0.0 requires illuminate/support ^8.0|^9.0 -> found illuminate/support[v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.0] but these were not loaded, likely because it conflicts with another require.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require pulkitjalan/google-apiclient:*" to figure out if any version is installable, or "composer require pulkitjalan/google-apiclient:^2.1" if you know which you need.
Call google sheet and error
Google_Service_Exception : {
"error": {
"code": 403,
"message": "The caller does not have permission",
"errors": [
{
"message": "The caller does not have permission",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
Just tried running "composer require pulkitjalan/google-apiclient" and got the following error:
Problem 1
- pulkitjalan/google-apiclient 2.0.1 requires google/apiclient 1.* -> no matching package found.
- pulkitjalan/google-apiclient 2.0 requires google/apiclient 1.* -> no matching package found.
- Installation request for pulkitjalan/google-apiclient ^2.0 -> satisfiable by pulkitjalan/google-apiclient[2.0, 2.0.1].
Looks like the google/apiclient package recently updated their version number. Assuming that's the issue here?
Thanks! Looking forward to getting your wrapped installed and playing around with it a bit!
Our project is currently running on vapor, Then we have a console command that will upload the file to google drive,
when we're running that command we always got Segmentation fault (core dumped).
above is the error i am getting.. why am i not getting the auth popup ? what am i doing wrong in here can you please explain ?
this is how i am making the request
$youtube = \Google::make('youtube');
$youtube->channels->listChannels(
'id,contentDetails',
[
'mine' => true
]
);
this is the config
'client_id' => env('GOOGLE_CLIENT_ID', ''),
'client_secret' => env('GOOGLE_CLIENT_SECRET', ''),
'redirect_uri' => env('GOOGLE_REDIRECT', ''),
'scopes' => [
'https://www.googleapis.com/auth/yt-analytics.readonly',
'https://www.googleapis.com/auth/yt-analytics-monetary.readonly',
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtubepartner',
],
'access_type' => 'online',
'approval_prompt' => 'auto',
Thank you !!
Hi,
On running composer require pulkitjalan/google-apiclient
I receive the following error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for pulkitjalan/google-apiclient 0.1.* -> satisfiable by pulkitjalan/google-apiclient[0.1.0].
- pulkitjalan/google-apiclient 0.1.0 requires google/apiclient dev-master -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Upon upgrading to package 3.* (now using google api 2.*) and running composer update
, the REST.php script in the google api library is throwing the following exception:
{ "error": "invalid_request", "error_description": "Required parameter is missing: grant_type" }
Here's a bit of my stacktrace
No. | CALLED CODE | DOCUMENT | LINE |
---|---|---|---|
56 | Google_Http_REST::decodeHttpResponse(…) | ~/plugins/samschneider/blogger/vendor/google/apiclient/src/Google/Http/REST.php | 94 |
55 | Google_Http_REST::doExecute(…) | ||
54 | call_user_func_array(…) | ~/plugins/samschneider/blogger/vendor/google/apiclient/src/Google/Task/Runner.php | 181 |
53 | Google_Task_Runner->run() | ~/plugins/samschneider/blogger/vendor/google/apiclient/src/Google/Http/REST.php | 58 |
52 | Google_Http_REST::execute(…) | ~/plugins/samschneider/blogger/vendor/google/apiclient/src/Google/Client.php | 779 |
51 | Google_Client->execute(…) | ~/plugins/samschneider/blogger/vendor/google/apiclient/src/Google/Service/Resource.php | 232 |
50 | Google_Service_Resource->call(…) | ~/plugins/samschneider/blogger/vendor/google/apiclient-services/Google/Service/Blogger/Resource/Blogs.php | 44 |
49 | Google_Service_Blogger_Resource_Blogs->get(…) | ~/plugins/samschneider/blogger/components/bloggerRecentList.php | 186 |
I can't find many references in the google api docs themselves to grant_type
, so I'm not sure yet where the problem lies. But I am using an offline access_type and therefore pass a refresh token and access token. But everything works with the most recent 2.* version.
The following code does not allow for dynamic redirect_url
which means that if I have more than one domain running the website it will not work.
public function fetchAccessTokenWithAuthCode($code)
{
if (strlen($code) == 0) {
throw new InvalidArgumentException("Invalid code");
}
$auth = $this->getOAuth2Service();
$auth->setCode($code);
$auth->setRedirectUri($this->getRedirectUri());
$httpHandler = HttpHandlerFactory::build($this->getHttpClient());
$creds = $auth->fetchAuthToken($httpHandler);
if ($creds && isset($creds['access_token'])) {
$creds['created'] = time();
$this->setAccessToken($creds);
}
return $creds;
}
Can we have the above changed to this:
public function fetchAccessTokenWithAuthCode($code, $redirectUrl = null)
{
if (strlen($code) == 0) {
throw new InvalidArgumentException("Invalid code");
}
$auth = $this->getOAuth2Service();
$auth->setCode($code);
$auth->setRedirectUri($redirectUrl ?? $this->getRedirectUri());
$httpHandler = HttpHandlerFactory::build($this->getHttpClient());
$creds = $auth->fetchAuthToken($httpHandler);
if ($creds && isset($creds['access_token'])) {
$creds['created'] = time();
$this->setAccessToken($creds);
}
return $creds;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.