I am trying to create a plugin for WordPress using the Google Analytics Reporting API v4 https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php
We need to load the Google API PHP Client Library
require_once __DIR__ . '/vendor/autoload.php';
I have downloaded the latest release of Google API https://github.com/google/google-api-php-client/releases but the vendor folder contains more than 7000 files!
My question is if I am doing something wrong here or I am missing something? Inside the vendor folder I can see all the Google services. How I can use the Google API with less files in a WordPress plugin? I will appreciate any help to the right direction.
By default the Google/Service directory contains all the code needed to access every Google Discovery services API. You don't technically need all of the files. You can safely delete everything under Google/Service that you don't need.
Dont delete files from any of the other directories. Just remove the unneeded APIs.
Related
I am using Google API client 2.0 and want to upgrade Google drive API from V1 to V2 to newer. I not found any straight forward way to upgrade version. Only the change log from google developer site found. Please tell me upgrade process guideline or step by step process.
Thanks in advance.
I am not sure i understand your question. Are you using the V2 of the Google drive api and now you want to upgrade to Google Drive V3? There are a lot of changes your going to have to make I don't think there are any guides on how to do it. Assuming you are using the Google PHP client library your best option will be to download the library for v3 and start fixing your errors one at a time. Like i said there are a number of changes in the library mainly title vs name. That and the library doesn't by default return all the fields your going to have to start using the field parameter.
When you download the library with composer you will be downloading the latest code for use with the Drive API v3. The Authencation code you have been using probably hasnt changed. All of the methods you use in drive probably have. Drive.php
Again there is no upgrade function for this its a completely different API. There is no way to upgrade it. You download the new class using composer and change your code as needed
I made a WP plugin which depends on the Youtube API. So, to do it well, I use Google API PHP client.
My issue is quite simple: the Google API PHP client is huge (more than 12 000 files), including clients for all Google services, when I just need to use Youtube service. So I'm not confortable committing all those files to the WP plugins repo when most of them are useless in my case.
So, right now, my composer.json looks like this:
{
"require": {
"google/apiclient": "^2.0"
}
}
Any way to use only the Youtube API client (using composer if it's possible)?
This is not for the feign of heart but it is doable.
Go to this branch of the repo https://github.com/google/google-api-php-client/tree/v1-master
Grab the full src/Google directory you will need all of that.
In the src/Google/Service directory is the stuff for all the different APIs. Remove everything except for YouTube.
cross your fingers it should work.
This wont remove all 12000 files but it should give you just what you absolutely need. I used to do this but its been a few years.
Unfortunately, I don't think this is possible without manually including the relevant files in your project (which is a really bad idea).
The reason why its impossible, is because Google places all service APIs for the PHP library in a single GitHub repository found here:
https://github.com/google/google-api-php-client-services
If Google does split them into multiple repositories, then it could be possible to include a single repo.
For now, though, all services are under one composer project and one repo. Maybe its worth making a GitHub issue to ask Google about this?
I just follow the instructions provided by google team, to communicate with the shopping API:
https://developers.google.com/api-client-library/php/auth/service-accounts
Everything works fine, I complete my integration (API for Shopping), nevertheless I realise now that when I download this google library, using composer:
composer require google/apiclient:^2.0
I have now around 6300 files to commit!!!
So, I will like to try to remove what for sure I will not need, since I just use API for google Shopping.
This is my current vendor/ ( or lib/) folders structures:
This a sample of my code that is already working correctly:
require_once __DIR__.'/lib/autoload.php';
$client = new Google_Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
$client->useApplicationDefaultCredentials();
$client->setScopes('https://www.googleapis.com/auth/content');
$client->fetchAccessTokenWithAssertion();
$service = new Google_Service_ShoppingContent($client);
Even I never use some of features directly located in other folders (ex: monolog, etc), I'm not sure if they are or not necessary (I suppose not) for google api.
So I will like to have confirmation, of the folders that could be removed safely and everything that allow google api shopping works correctly are not affected.
All of those files are required dependencies of the google API project. You should never commit composer's vendor directory into your VCS repository. You should utilize the feature of your VCS for ignoring files/directories to prevent you from accidentally committing those dependency files.
Good day, I am currently a noob in Google Drive SDK and I am planning to integrate it in my webapp. I checked out google-api-php-client from their svn and I noticed it's a bit large to include it all in my project (it's 5.6 mb). Excluding all but the src folder, it's still large for me (3.9 mb). I want to include only the files needed for the Google Drive integration to work. But I do not know what files do these two (Google_Client.php and Google_DriveService.php as in Google Developers' sample) depend on.
Can you guys pinpoint what files (that are not related to Drive) I can safely delete? I really want the total file size to be as small as possible 'cause I believe that it can affect the project's loading time.
Thanks(and pardon my English)! :)
Only checkout the library source code and remove all services other than Drive and Oauth2:
svn checkout http://google-api-php-client.googlecode.com/svn/trunk/src
Remove all files under src/contrib but preserve the following:
src/contrib/Google_DriveService.php
src/contrib/Google_Oauth2Service.php
Hi I am really struggling with this one.
I am developing with Google Analytics and Google Adwords; and I am using two separate Oauth libraries in the API Helper Libraries that are written by Google. One is an extension (oauth.so) for Adwords and the other is just a PHP class for Analytics.
When I alter my php.ini file to load the extension, my Analytics OAuth breaks. I think it maybe a conflict of the class names? I have tried changing the name, but haven't had any luck. I had thought that I came up with a solution: Using the dl() function to dynamically load the oauth.so extension on just the Adwords related pages (they are separate scripts):
dl('oauth.so');
Which works great on the command line! But it doesn't work in the browser. I refuse to believe that nobody has come across this issue before. I know that loading the extension from php.ini works in the browser, it just disables the Analytics class. Any one with experience with this, I'd love to hear your input, if you have any suggestions please feel free!
Thank you
The AdWords API PHP client library has been updated to allow for different OAuth libraries:
http://code.google.com/p/google-api-adwords-php/source/detail?r=178
You could even write your own OAuthHandler class that utilized the existing OAuth library that the Analytics library uses.
It's been removed from some SAPI's, either switch to CGI for the webserver (brr), or try to fix the problem with your Analytics PHP class.