Showing posts with label ClientLogin. Show all posts
Showing posts with label ClientLogin. Show all posts

Accessing a feed using ClientLogin & Ruby


Example of accessing the DocList API using ClientLogin in Ruby:
require 'net/http'
require 'net/https'
require 'cgi'
require 'rubygems'
require 'xmlsimple'
require 'pp'

def get_feed(uri, headers=nil)
  uri = URI.parse(uri)
  Net::HTTP.start(uri.host, uri.port) do |http|
    return http.get(uri.path, headers)
  end
end

email = '[email protected]'
password = CGI::escape('pa$$word')
service = 'writely'
source = 'MyCompany-MyApp-0.1'
path = '/accounts/ClientLogin'

data = ["accountType=HOSTED_OR_GOOGLE", 
        "Email=#{email}",
        "Passwd=#{password}",
        "service=#{service}",
        "source=#{source}"].join('&')

http = Net::HTTP.new(host='www.google.com', port=443)
http.use_ssl = true
http.start

headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
resp, data = http.post(path, data, headers)

token = data[/Auth=(.*)/, 1]  # parse out the Auth token

headers['Authorization'] = "GoogleLogin auth=#{token}"
resp = get_feed('http://docs.google.com/feeds/documents/private/full', headers)

doc = XmlSimple.xml_in(resp.body, 'KeyAttr' => 'name')
pp doc

Force PHP to use a Google Account in ClientLogin


Sometimes you have a Google Apps account that is also registered as a Google Account and you want to make sure you are logging in as the Google Account, especially when you want to use a service like Picasa Web Albums that does not have an Apps version. To do this using ClientLogin you need to do something like:
$serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$username = "[email protected]";
$pass = "password";
$accountType = "GOOGLE";


$client = Zend_Gdata_ClientLogin::getHttpClient($username, $pass, $serviceName, null, Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null, Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, $accountType);

Perform ClientLogin using curl


Requests an authorization token for one of the Google Data API services and stores it in the shell environment variable GDATA_AUTH. This shell script takes three command line parameters, the email address for the desired account, password, and the service name of the service which the token will be used to access.
#!/bin/sh
export GDATA_AUTH=`curl 2>/dev/null https://www.google.com/accounts/ClientLogin \
  -d Email=$1 -d Passwd=$2 -d accountType=HOSTED_OR_GOOGLE -d source=curlExample \
  -d service=$3 | grep '^Auth=' | cut -c 6-`
echo $GDATA_AUTH