BLOG HAS NEW ADDRESS

BLOG HAS BEEN MOVED TO www.BestFromGoogle.blogspot.com

Showing posts with label Google Latitude Api. Show all posts
Showing posts with label Google Latitude Api. Show all posts

Friday, April 22, 2011

Google Latitude : Ruby on Rails Example using Oauth


 Click Like If you Agree

Spent a few days searching for  Google Latitude example
RUBY on RAILS and I am happy to say finally found a
good post on Google Latitude . I thought it would be great
to include this one in  my blog as it already contained a lot of
stuff on Google Latitude .

Register Domain with Google


1) Go to: https://www.google.com/accounts/ManageDomains
    Add a domain name if you have or
    Get cheap and good web hosting ($7.99 per year)
    Thats the cheapest price you can get on the web with
    a large no of of features .
    Hosting Includes 99.9% Uptime, RV Site Builder, 
    Fantastico Deluxe Scripts, Softaculous Auto Script  
    Installer, Ruby On Rails, Ruby Gems, Virus Scanner,
    WHM cPanel w/ZamFoo 7.1, CGI, Perl, PHP 5, cURL &
    GD, suPHP. 
    
    They are not that famous I guess but definitely a good one. 
 










 After registering your domain , the next step is to create 
 an pair of RSA keys , this one is needed for encryption
 of the data to be send during the OAuth Handshake .


In linux and OS X you can use openssl
openssl req -x509 -nodes -days 365 -newkey rsa:1024 
-sha1 -subj ‘/C=US/ST=CA/L=San 
Francisco/CN=example.com’ -keyout rsakey.pem -out 
rsacert.pem

Upload the rsacert.pem, and keep the rsakey.pem in a

safe place.  For the Target URL path prefix, Just add 
the domain name. 

Get the Oauth Consumer Key and Secret .


2) OAuth GEM



Include in your environment.rb

config.gem "oauth"
You need to install it to use in your system .
Recommended version 0.4.1 .

3) Generate OAuth Access Toke Model 


$ ruby script/generate model OAuthAccessToken
Note: I've done this because I don't want to store 
my access token directly in my User model.  This
gives me the option of having tokens for multiple 
scopes for a user through a polymorphic association.

Migration:

create_table :oauth_access_tokens do |t|
      t.string  :oauth_token, :oauth_secret, :scope
      t.string  :subject_type, :limit > 30 #for polymorphic association
      t.integer :subject_id
      t.timestamps
end  


4)User Model 


has_one  :latitude_access_token, 
:model_name => 'OAuthAccessToken',
:as => :subject, :conditions => ['scope = ?','latitude']


5)Setup OAUTH Consumer for Latitude


Create class lib/o_auth_consumers.rb


class OAuthConsumers  

  Latitude = OAuth::Consumer.new( CONSUMER_KEY, 
      CONSUMER_SECRET, {
      :site => "https://www.google.com",
      :request_token_path => "/accounts/OAuthGetRequestToken",
      :access_token_path => "/accounts/OAuthGetAccessToken",
      :authorize_path=> "/latitude/apps/OAuthAuthorizeToken",
      :signature_method => "RSA-SHA1",
      :private_key_file => "#{RAILS_ROOT}/config/rsakey.pem" 
       #path to my rsakey that I saved earlier
  }) 

end

Remember to change the CONSUMER_KEY and 
CONSUMER_SECRET which you got from step1.

6)Generate Controller for APP

ruby script/generate controller latitude

require 'oauth'
require 'oauth/signature/rsa/sha1'
class LatitudeController < ApplicationController


def index
    #check the user has a latitude oauth access token
    if current_user.latitude_access_token
      token = 
     OAuth::Token.new(current_user.latitude_access_token.oauth_token,     current_user.latitude_access_token.oauth_secret)
      @request = JSON.parse(OAuthConsumers::Google.request('get', "https://www.googleapis.com/latitude/v1/currentLocation", token).body)
      @lat = @request['data']['latitude']
      @lng = @request['data']['longitude']
      @time = Time.at((@request['data']['timestampMs'].to_i)
       /1000).strftime('%b %d, %Y - %T')
    else
      redirect_to :action => 'authorise'
    end
    
  end

 def authorise
 if !params[:oauth_token]


request_token = OAuthConsumers::Latitude.get_request_token(
{ :oauth_callback => "http://localhost:3000/latitude/authorise" },
{ :scope => "https://www.googleapis.com/auth/latitude" }
                        )


session[:oauth_secret] = request_token.secret
      redirect_to request_token.authorize_url + 
      "&domain=example.com&granularity=best&location=all"
      else
      request_token = OAuth::RequestToken.new(
                         OAuthConsumers::Latitude,
                         params[:oauth_token],
                         session[:oauth_secret]
                       )
 begin
        access_token = 
        request_token.get_access_token(
         :oauth_verifier => params[:oauth_verifier] )
        rescue
        redirect_to :action => 'index'
      end

if access_token
        #now save the access token for this user 
        OauthAccessToken.create :subject => current_user,
                                :scope => 'latitude',
                                :oauth_token => access_token.token,
                                :oauth_secret => access_token.secret
      end

   redirect_to latitude_path
    end
  end
  
end

7) Get the Latitude To Work 

That's pretty much it.  Go to http://localhost:3000/latitude,
you will be directed to Google to authorise your account, 
then once that all goes through, you will be sent back to 
your app, an Access Token will be created which will be 
stored for your user.  I'm not exactly sure how long this 
lasts at the moment, but I'm testing that right now and 
will update if I find anything important.



Thanks to Ben Petro for creating the code on Ruby On Rails 
 platform .

Read more...

Thursday, April 14, 2011

Page Speed : Performance Analyzer from Google Labs

Page Speed another product from Google Labs , but this
time not of much use to the public , but a product
developed keeping the web developers in mind .

There exists two versions of this product
1) Page Speed Offline which you install into your
Chrome or Firefox Browser .
2) Page Speed Online which gives you the performance
report online .

We took the test and the site http://googlelatiude.blogspot.com/
got an rating of 86 out of 100 on desktop analysis & from mobile
point of view scored 80 out of 100 .

Page Speed did give us suggestions on how to improve the performance
and they were really informative .The suggestions were classified
as
  • High Priority
  • Medium Priority
  • Low Priority
Luckily we had hardly any High Priority Performance degrading factors
& we are working on Page Speed Suggestions .

With the massive shift in the internet users towards mobile , optimizing 
your website for mobile has become more crucial than doing for the
desktop pc. Page Speed provides you suggestions on how to improve
your site performance for mobile devices .

Check out the Page Speed Home Page 

Read more...

Monday, April 11, 2011

Twitter used for Email Harvesting!!!!


 Click Like If you Agree
Your favourite social networking site Twitter can now be used for
Email Harvesting making it a threat to your online security and
privacy . Well even I was shocked to learn this at the first place
when I learnt how simple it was !!!

Social Networking site Twitter has this great feature of searching
twitter for the latest twitter updates at http://search.twitter.com/
Just go to this twitter search page , enter your search keyword and
there you have the latest tweets on twitter regarding the keyword
you have searched .




Spammers use the same technique for Email Harvesting  .In your
twitter search box type in @gmail.com OR @yahoo.com OR
the keyword mail me at and you can get the list of Email address
in your twitter search page .  People tweeting usually have this bad
habit of leaving their email address in their tweets while tweeting and
this eventually becomes a threat to their online privacy .Email Harvetsers
can write a simple program that runs every X seconds fetching them
new email address . So the next time you leave your Email address
online in Twitter or any of the Web directories ,get ready to be the
target of the spammers .

Read more...

Google Groups targetted for Email Harvesting!!!

Email Harvesting??
Well to many who dont have much idea what email harvesting is ,
let me put it down in few words. E-mail harvesting is the process
of obtaining lists of email address using various methods for use in
bulk email or other purposes usually grouped as spam. 


Why is Email Harvesting done for ??


Email Harvesting is a great tool that can be used to market your 
product .You get a list of email address using Email Bots that 
crawl the web to get the email address from different websites
all over the web .




What are the tools available for Email Harvesting ?? 


  • Email Grabber 
  • GSA Email Spider
  • Email Extractor
Google Groups a Target of Email Harvesting??

 I recently found a great increase in spam in my inbox & 
liitle research on Google showed me Google groups was
one of the major targets of Email Harvesting Bots  .The major
reason for it being targetted was some of the google groups 
used to make their posters email address publicly visible ,
this would make it easy for the spammers extract the email
address.Still the question remained was how were the spam
mail being sent ending up in my Gmail Inbox rather than the
Gmail Spam section?? The spammers joined this group using 
their spam email address & hence they could easily bypass the
Gmail's Spam Filter which resulted in spam reaching your inbox.

Read more...

Sunday, March 20, 2011

Google Latitude Mashup With Google maps




My Second post was on getting the user's location using
google latitude/badge api .This thread is definitely a
continuation of the earlier post , here i will show you how
to display the user location on google maps .

For that we will be using a jquery plugin called JQUERY:GMAP3

Step1
Create a php file that will return the latitude & longitude
Step2 
Make an ajax call to the php file
Step3 
Display the google latitude result on google maps

Step1

######getposition.php #######

<?php
//Replace the YOURUSERID in the url below with your Badge userid . 
$url="http://www.google.com/latitude/apps/badge/api?user=YOURUSERID&type=json" ;
// We get the content
$content = file_get_contents( $url );
print($content); //This will return the data in json format
?>

Step 2 & Step3

For the ajax calls we will be using jquery functionalities directly ,a call
will be made to the php page, which will return me data in json format
which we will parse using jquery parseJSON() function .After this  using
the jquery GMAP3 library(http://plugins.jquery.com/project/gmap3)
we will be displaying the marker on google map .



#### Showmap.html ######

<html>    
  <head> 
    <script type="text/javascript" src="jquery-1.4.4.min.js"></script>        
    <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
    <script type="text/javascript" src="gmap3.js"></script> 

    <style>
      .gmap3{
        margin: 20px auto;
        border: 1px dashed #C0C0C0;
        width: 500px;
        height: 250px;
      }
      #container{
        overflow: auto;
        text-align:center;
        width: 100px;
        margin: 20 auto;
      }
      .box{
        float: left;
        width: 20px;
        height: 20px;
        margin-left: 20px;
        background-color:#FFF;
        border:1px solid #000;
      }
    </style>
    <script type="text/javascript">   

      $(function(){
// ajax call to the php page   
$.ajax({
type: "POST",
url: "getposition.php",
success: function(msg){
var obj=$.parseJSON(msg);
// Parse data recived .For more details check  //http://api.jquery.com/jQuery.parseJSON/
var latitude=obj.features[0].geometry.coordinates[1];
var longitude=obj.features[0].geometry.coordinates[0];
var coord=new google.maps.LatLng(latitude,longitude); 
$('#test1').gmap3(
{ action: ':addMarker',
latLng: coord,
map:{
center: true,
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROAD
}
}
);
}
});
      });
    </script>  
  </head>
  <body>
    <div id="test1" class="gmap3"></div>
  </body>
</html>

This was just a basic mashup of google latitude & google maps .
If you want to use all the functionalities of google maps you can
which has clear explanation of using google maps jquery plugin.

If you have still queries about this thread , please do comment .



Read more...

Saturday, March 19, 2011

Easier way to use Google Latitude


 Click Like If you Agree
Hi Everyone ,

My first post was about getting the Location using Google Latitude Api using OAUTH,

it is extremely useful when you want to create an application that gets your app users

location and you can mashup with google maps api or yahoo maps to create killer apps .

But if you are creating a system in which you create google latitude account for your

customers  or you want to track your kids from your home , there's  a simpler method

 for doing that , a shortcut rather than going the OAUTH way i.e. Google Latitude Badge .

Step 1

Log into your google account through which you are linked to Google Latitude

Step 2

Goto https://www.google.com/latitude/b/0/apps



Read more...

Sunday, October 17, 2010

Steps to get OAuth Playground working for Google Latiude

Step 1: You must have a domain registered with Google here:https://www.google.com/accounts/ManageDomains
This is how Google identifies your application, even if it's an installed program, not a web app. Once your domain is registered, take note of your OAuth Consumer Key and OAuth Consumer Secret, you'll need  them later.
You can also register at google appengine if your creating an application and don't have a domain .

 Step 2: Now you can go to the OAuth Playground:http://googlecodesamples.com/oauth_playground/

 Scope: Nothing checked  

 Modify OAuth Parameters
 oauth_signature_method: HMAC-SHA1
 oauth_consumer_key: <yours from domain registration>
 consumer secret: <yours from domain registration>
 oauth_token_secret: <blank>
 oauth_token: <blank>



 Step 3 :
 Click "Request Token."  oauth_token_secret and oauth_token are now
 filled in, and you have an unauthorized request token.

Step 4 :

 Google Latitude uses a different Authorization endpoint than other
 Google services!
When you click the "Authorize" button, your browser will redirect tohttps://www.google.com/accounts/OAuthAuthorizeToken&oauth_token=token....
YOU MUST NOW CHANGE THE URL
http://www.google.com/latitude/apps/OAuthAuthorizeToken?domain=example.com&oauth_token=token
Keep the oauth_token parameter the same, but change the URL, and add
the Latitude-specific parameters discussed in the "Using REST"
document:http://code.google.com/apis/latitude/v1/using_rest.html#auth
Once you're on that Authorization Service page, click "Grant access."
You'll be redirected back to OAuth Playground


Step 5:
You can now exchange your Authorized Request Token for an Access
Token. Click the "Access Token" button. 
If it fails just redo the steps and I think it should be fine .

Step 6 :

In the Drop down box Slect Get Option and enter the URL

This should return you a JSON result that will return your current location .

Actually Google gives you different options to set location 
1) Either through a GPS enabled mobile phone or 
2) You can set it manually using the iGoogle Latitude widget .

I hope this will be helpful for someone who is creating Apps with
Google Latitude Api

Thanks,,,

Vaishakh 

Read more...

About This Blog

This Tech Blog is about a month old and increasing
number of pageviews and a steady increase in
our loyal readers has prompted us in writing
unique articles that will be of great use to all the
webmasters .The blog currently has only 15+
unique google tricks and hacks , we will be adding
new tricks as and when we stumble upon something
useful to our readers .

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP