First, i just want to say what information i am needing to get from the user.
To get all of this information, i went ahead and download/installed the PHP-Client Library located here.
Since this is my first time using the API, i looked around and found the following scopes:
$client->setScopes(array('https://www.googleapis.com/auth/youtube.readonly', 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'));
For some reason, when i run this: $myData = $GoogleData->userinfo->get('me');
i get this:
Undefined property: Google_Service_Plus::$userinfo in path/test.php on line 61
Not too sure what i am doing wrong, or even if i should be using the Google Plus Api to get this information.
I need the Main Account email (Contains all youtube channels) and the users address, etc. That they signed up in their Google Account. How do i get this information and what am i doing wrong in my above example?
I have actually created a chat room dedicated to all things Google API (Go here)
This also brings me to another point. Why is the documentation sooo outdated and not taken care of. Most of the examples that i see are from two years ago, but i am using something that has been updated a couple months ago.
Using the new version of the PHP library (currently 1.0.4-beta on GitHub):
require_once 'lib/Google/Client.php';
require_once 'lib/Google/Service/Plus.php';
$google_client = new \Google_Client;
$google_client->setClientId(GOOGLE_CLIENT_ID);
$google_client->setClientSecret(GOOGLE_CLIENT_SECRET);
$google_client->setRedirectUri(GOOGLE_REDIRECT_URI);
$google_client->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
$google_client->setAccessType = 'offline';
// Either call:
// $google_client->authenticate($auth_code);
// with the $auth_code returned by the auth page or
// $google_client->setAccessToken($existing_token);
// with a previously generated access token.
$plus = new \Google_Service_Plus($google_client);
$person = $plus->people->get('me');
print_r($person);
The scope should be "https://www.googleapis.com/auth/plus.login" (I only tested with the "profile" scope, because I don't have a Google Plus profile).
To get the YouTube channels, you'd have to add the scope "https://www.googleapis.com/auth/youtube" and use the channels#list method, with the 'mine' parameter set to true. The class in the PHP lib is 'Google_Service_YouTube'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With