Skip to content

Instantly share code, notes, and snippets.

@gotakk
Forked from Remiii/README.md
Last active August 29, 2015 14:16
Show Gist options
  • Save gotakk/abe4349ae501bee01511 to your computer and use it in GitHub Desktop.
Save gotakk/abe4349ae501bee01511 to your computer and use it in GitHub Desktop.

GENERATING A REFRESH TOKEN

STEP 1

  • Go to http://cloud.google.com/console and log-in
    • Activate youtube-data API (APIs & auth -> APIs)
    • Register a new app (APIs & auth -> registered apps)
      • Name it, select native
      • Write down your client-id and client-secret

Marks: https://developers.google.com/console/help/new

  • Set $client_id and in step1_url.php and step2_refresh_token.php

  • $ php step1_url.php and open the url in your browser

    • Write down the auth code ('code' in step2_refresh_token.php).
  • Set 'client_secret' and 'code' in step2_refresh_token.php

  • $ php step2_refresh_token.php

    • Write down your refresh token
  • Save your client-id, client-secret and refresh-token

See more info on this thread: http://stackoverflow.com/questions/8257678/google-calendar-api-v3-hardcoded-credentials

See more info about client scret: http://stackoverflow.com/questions/15547019/how-do-i-find-the-googles-oauth-2-0-client-secret-key-for-developing-chrome-ext

#!/usr/bin/php
<?php
$client_id = 'yourClientId' ;
$params = array(
'response_type' => 'code',
'client_id' => $client_id,
'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob',
'scope' => 'https://www.googleapis.com/auth/youtube.upload',
) ;
$url = 'https://accounts.google.com/o/oauth2/auth?' . http_build_query($params) ;
echo $url . "\n" ;
?>
#!/usr/bin/php
<?php
$url = 'https://accounts.google.com/o/oauth2/token' ;
$post_data = array(
'code' => 'yourAuthCode',
'client_id' => 'yourClientId',
'client_secret' => 'yourClientSecret',
'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob',
'grant_type' => 'authorization_code',
) ;
$ch = curl_init() ;
curl_setopt($ch, CURLOPT_URL, $url) ;
curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;
$result = curl_exec($ch) ;
$token = json_decode($result) ;
print_r($token) ;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment