Example #1
0
/** I hope you are here by creating google web application, obtaining clientID and client secrete
 * if not, got to Google developer console and create app under an API Manager menu
 *
 */
session_start();
//include google api library
include 'vendor/autoload.php';
//or wherever autoload.php is located
$google_client_id = 'your Application client ID';
$google_client_secret = 'your client secrete key';
$google_redirect_uri = 'uri to process response form google';
// either self or other php file eg. http://localhost/appname/output.php -- for local machine
//setup new google client
$client = new Google_Client();
$client->setApplicationName('your application name');
$client->setClientid($google_client_id);
$client->setClientSecret($google_client_secret);
$client->setRedirectUri($google_redirect_uri);
$client->setAccessType('online');
$client->setScopes('https://www.google.com/m8/feeds');
$googleImportUrl = $client->createAuthUrl();
// creating a curl function
function curl($url, $post = "")
{
    $curl = curl_init();
    $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
    curl_setopt($curl, CURLOPT_URL, $url);
    //The URL to fetch. This can also be set when initializing a session with curl_init().
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
Example #2
0
 /**
  * @return \Google_Client
  */
 public static function get_drive_client()
 {
     $client = new \Google_Client();
     $client->setApplicationName('My WP Backup');
     $client->setClientid(base64_decode('ODkwOTA4NDc4NDUzLXNhN3MybHU4ZzVidnBrNXYxMTM2ODJpNmtpdmEyMzEzLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29t'));
     $client->setClientSecret(base64_decode('amp6ek04QUxJd0sxTW5DNjJBbDRlUmFG'));
     $client->setScopes(array('https://www.googleapis.com/auth/drive'));
     $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
     $client->setAccessType('offline');
     return $client;
 }