Skip to content

Instantly share code, notes, and snippets.

@ianbarber
ianbarber / gist:5170508
Last active December 29, 2023 03:42
Example Sign In activity for Google Sign-In on Android that retrieves an authorization code for use with server side authentication. See http://www.riskcompletefailure.com/2016/07/server-side-google-api-access-from.html for more background and links.
package com.example.anothersignintest;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.OptionalPendingResult;
import com.google.android.gms.common.api.ResultCallback;
#ifdef APP_DEFINE_CONSTANTS
#define EXTERN
#define INITIALIZE_AS(x) =x
#else
#define EXTERN extern
#define INITIALIZE_AS(x)
#endif
EXTERN const double kAppFirstConstant INITIALIZE_AS( 0.025);
EXTERN const double kAppOtherConstant INITIALIZE_AS( 1.1);
@ianbarber
ianbarber / RetrieveAccessTokenActivity.java
Created March 17, 2014 20:22
A quick example of retrieving an access token with GoogleAuthUtil
package com.google.devrel.samples.gmstest.app;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ianbarber
ianbarber / calcreate.php
Created November 28, 2012 12:19
Create hangout link via calendar
<?php
/*
* example usage:
* First call to get the url
* php calcreate.php
* After authorising, grab the code from the redirect URL
* php calcreate.php "long_code_value_from_oauth_callback"
* This will var_dump out the new calendar entry
*/
require_once 'google-api-php-client/src/Google_Client.php';
@ianbarber
ianbarber / simplepub.php
Created June 21, 2013 15:17
A noddy implementation of ZMTP 3.0 in PHP http://rfc.zeromq.org/spec:23
<?php
include_once "zmtp.php";
// This was connecting to a libzmq master based subscriber.
$host = "127.0.0.1";
$port = 4422;
// Connect and send null mechanism.
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$rc = socket_connect($socket, $host, $port);
@ianbarber
ianbarber / CodeActivity.java
Last active June 10, 2018 13:10
Example of handling both client and server sign in with GoogleAuthUtil and GoogleApiClient
package com.google.plus.sample.ShareTest;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
@ianbarber
ianbarber / anon2.html
Created July 29, 2013 15:01
X-Has-Session example
<html><head>
<title>OpenID X-Has-Session</title>
</head>
<body>
<div id="msg"></div>
<script>
if (window.location.href.indexOf("openid.mode=") != -1) {
if (window.location.href.indexOf("x-has-session") != -1) {
document.getElementById("msg").textContent = "You be logged in";
@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 / anon.html
Created July 29, 2013 14:20
Check Session State example
<html><head>
<title>checkSessionState Example</title>
<script>
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?onload=OnLoadCallback';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
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>() {