Skip to content

Instantly share code, notes, and snippets.

if (opr.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly. We can try and retrieve an
// authentication code.
GoogleSignInResult result = opr.get();
handleSignInResult(result);
} else {
// If the user has not previously signed in on this device or the sign-in has expired,
// this asynchronous branch will attempt to sign in the user silently.
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
mGoogleApiClient = new GoogleApiClient.Builder(this /* Context */)

.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)

.addApi(Auth.GOOGLE_SIGN_IN_API, gso)

.build();

OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);

GoogleSignInAccount acct = googleSignInResult.getSignInAccount();
String authCode = acct.getServerAuthCode();
@ianbarber
ianbarber / ViewController.swift
Created March 17, 2015 20:14
ViewController for GIDSignIn example
class ViewController: UIViewController, GIDSignInDelegate {
@IBOutlet weak var signInButton: GIDSignInButton!
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().delegate = self
// Test to see if we are signed in on load.
GIDSignIn.sharedInstance().signInSilently()
}
@ianbarber
ianbarber / AppDelegate.swift
Created March 17, 2015 20:12
Simple app delegate for Swift and GIDSignIn
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
GIDSignIn.sharedInstance().clientID = "366667191730-38onttdkl2cpqstheip1ek3r5tb8s5ds.apps.googleusercontent.com";
return true
}
@ianbarber
ianbarber / drive.php
Created March 3, 2015 17:53
Query Drive with a service account
<?php
require_once "../vendor/autoload.php";
$client = new Google_Client();
$client->setApplicationName("Service Acccount Test");
$client_id = '985145966381-is5nq94smihmoa2k0567jab6u6vj278c.apps.googleusercontent.com';
$service_account_name = '985145966381-is5nq94smihmoa2k0567jab6u6vj278c@developer.gserviceaccount.com';
$key_file_location = 'foostarter-a27f84b2dec4.p12';
@ianbarber
ianbarber / analytics.php
Created March 3, 2015 16:24
Query Analytics with Service Account
<?php
require_once "../vendor/autoload.php";
$client = new Google_Client();
$client->setApplicationName("Service Acccount Test");
$client_id = '985145966381-is5nq94smihmoa2k0567jab6u6vj278c.apps.googleusercontent.com';
$service_account_name = '985145966381-is5nq94smihmoa2k0567jab6u6vj278c@developer.gserviceaccount.com';
$key_file_location = 'foostarter-a27f84b2dec4.p12';
[deviceManager launchApplication:applicationID
withLaunchOptions:[[GCKLaunchOptions alloc] initWithLanguageCode:nil
relaunchIfRunning:YES]];
- (void)deviceDidGoOffline:(GCKDevice *)device {
[self performSelector:@selector(updateCastIconButtonStates) withObject:nil afterDelay:0];
}