I want to be able to query the Gmail API through a HTTP GET request.
I'm trying to query the Gmail API to get a message unread count from my INBOX label.
API Reference : https://developers.google.com/gmail/api/v1/reference/users/labels/get
The API reference shows the following HTTP request to get the unread count.
GET https://www.googleapis.com/gmail/v1/users/userId/labels/id
The API reference also says you need authorization through OAuth 2.0.
I managed to get examples working in the PHP library to successfully query the API but there is not enough PHP documentation to write any specific code.
However the API reference lists all HTTP calls to access different parts of the API however I can't figure out how to use OAuth (Access Tokens) with these HTTP requests?
The official PHP client library comes with a few examples like this one that shows you how to authenticate using OAuth. The API documentation also has a lot of information about this process.
To get the unread messages count, you should do something like this:
// $googleClient is an authenticated instance of 'Google_Client'
$gmail = new \Google_Service_Gmail($googleClient);
$label = $gmail->users_labels->get('me', 'INBOX');
$unreadCount = $label->messagesUnread;
You might have to turn 'Conversation view' off in the Gmail settings for this to return an accurate result.
Accessing the Gmail API in php should be similar to other Google APIs from php. Maybe look at quickstart examples from the calendar or Google Drive APIs in PHP and work from there?
If you have the oauth2 access token you can often just put it in the "Authorization" header. c.f. https://www.rfc-editor.org/rfc/rfc6750#section-2.1
Though honestly, I think it'll be a lot easier long-term to figure out how to do it with the PHP Google APIs library...
Related
I'm currently working with Google API through this great php library but it doesn't support the last API and most of his method are going to be deprecated.
I already developed the Google authentication.
I now need to get the list of the locations managed by the authenticated Google account.
I'm quite sure I need to call this api but I need to do it through the official PHP library.
Unfortunately there isn't any documentation of this PHP library so I tried different approach but I was never able to get them.
Here one of my attempt:
$client = new Google_Client();
$client->setAuthConfig($this->CLIENT_SECRET_PATH);
$client->addScope(self::GOOGLE_CLIENT_SCOPE);
$client->setAccessToken($this->gmb_access_token);
$this->gmb_client = new Google\Service\MyBusinessBusinessInformation($client);
$account_locations = $this->gmb_client->accounts_locations->getLocations;
But the response is empty.
Any help would be really appreciated.
I've played around the the Analytics API and used oauth and managed to pull data from my Analytics account, this wasn't too much of a bother and worked really well.
The problem is I'm building a small "data graphing" service for me clients, this will basically feed data from Google Analytics, Telephone tracking and a few other services into a central area that'll display how many people are contacting them from their website.
The problem is that to use the Google Analytic API you need to be authenticated by oauth, this prompts the user to log into a Google account.
Is there a way in which I can get my GA data without the need to manually authenticate with oauth?
You could try GAPI - Google Analytics API PHP Interface
Here's the Google Code page of this project:
http://code.google.com/p/gapi-google-analytics-php-interface/
Features (as mentioned on the GAPI project page):
Supports CURL and fopen HTTP access methods, with autodetection
PHP arrays for Google Analytics metrics and dimensions
Account data object mapping - get methods for parameters
Report data object mapping - get methods for metrics and parameters
Easy filtering, use a GAPI query language for Google Analytics filters
Full PHP5 Object Oriented code, ready for use in your PHP application
I am looking for a good PHP based lib to send a message to new followers. Probably it's already done. I think it must work as a twitter client and not around OAUTH2 authentication.
Here is Twitter's list of PHP API's
http://dev.twitter.com/pages/libraries#php
You will have to use OAUTH2, otherwise you will not be able to send a message to followers.
I'm developing a PHP application to retrieve the list of contacts from a GMail account. I'm looking for a solution which would enable the user of my application to provide the login and password to their Gmail account in my application (as opposed to getting redirected to Google) and then automatically do the retrieval. The retrieval process can be run in PHP or JavaScript (which would then feed the list of contacts back to PHP using Ajax).
Is it possible to do that? Which JavaScript API should I use for that? Can someone point me at the right chapter in Google Contacts Data API documentation?
This is really not advised - google provide OAuth for a reason - so that users won't have to give their credentials to 3'rd parties.
Check out http://code.google.com/apis/accounts/docs/OAuth.html
Speaking only for my self (and all other developers I know), having to hand over my credentials to 3'rd parties is a real no-no.
It would be best to use the Google Contacts Data API using JavaScript for your case.
I haven't tested it myself but it looks nice: http://gmail-lite.sourceforge.net/wordpress/
//edit:
You probably should use: http://code.google.com/apis/contacts/
In one page on my personal site, I like to be able to see some data get from Google Analytics.
I like to have a list of all my site and the average visitor per week or per month over the current year
I have check some solution:
Yahoo Pipe (look complicated)
Google Analytics PHP API class(look nice)
Google Analytics API (look official)
Dimension Analyzer for Google Analytics(look fancy)
So at this point, it have done my research, but none give me something i like to have. Getting a JSON from google would be nice. I will have to parse a XML maybe, but i like to see simpler solutions.
ANYthing would be nice too see
The current version of the Core Reporting API supports this.
You can use the PHP client to access the API. You'll need to register your project in the API console to obtain OAuth 2.0 client ID and secret.