How to get Acces Token and refresh token for Fusion Api

145 views
Skip to first unread message

Severler

unread,
Dec 26, 2014, 5:36:19 PM12/26/14
to mitappinv...@googlegroups.com
Hello

I want build app using fusiontable as DB .And with out FusionT rotating icon and more usefull so ı need use oauth.

I know Tayfun's do it but its premium content

I need oauth verify for insert update or other actions

How can ı get acces token and refresh token 

#2. Your web application redirects the user to Google Authorization page
#3. User grants your web application access
print 'Visit the URL below in a browser to authorize'
print '%s?client_id=%s&redirect_uri=%s&scope=%s&response_type=code' % \
 
('https://accounts.google.com/o/oauth2/auth',
  client_id
,
  redirect_uri
,
 
'https://www.googleapis.com/auth/fusiontables')

#4. Google redirects the user back to your web application and
#   returns an authorization code
auth_code
= raw_input('Enter authorization code (parameter of URL): ')

#5. Your application requests an access token and refresh token from Google
data
= urllib.urlencode({
 
'code': auth_code,
 
'client_id': client_id,
 
'client_secret': client_secret,
 
'redirect_uri': redirect_uri,
 
'grant_type': 'authorization_code'
})
request
= urllib2.Request(
  url
='https://accounts.google.com/o/oauth2/token',
  data
=data)
request_open
= urllib2.urlopen(request)

#6. Google returns access token, refresh token, and expiration of
#   access token
response
= request_open.read()
request_open
.close()
tokens
= json.loads(response)
access_token
= tokens['access_token']
refresh_token
= tokens['refresh_token']

#7. Access token can be used for all subsequent requests to Fusion Tables,
#   until the token expires
request
= urllib2.Request(
  url
='https://www.google.com/fusiontables/api/query?%s' % \
   
(urllib.urlencode({'access_token': access_token,
                       
'sql': 'SELECT * FROM 123456'})))
request_open
= urllib2.urlopen(request)
response
= request_open.read()
request_open
.close()
print response

#8. When the access token expires,
#   the refresh token is used to request a new access token
data
= urllib.urlencode({
 
'client_id': client_id,
 
'client_secret': client_secret,
 
'refresh_token': refresh_token,
 
'grant_type': 'refresh_token'})
request
= urllib2.Request(
  url
='https://accounts.google.com/o/oauth2/token',
  data
=data)
request_open
= urllib2.urlopen(request)
response
= request_open.read()
request_open
.close()
tokens
= json.loads(response)
access_token
= tokens['access_token']

How to apply it to app inventor 

Can someone help me?

Taifun

unread,
Dec 26, 2014, 7:21:28 PM12/26/14
to mitappinv...@googlegroups.com
well, my fusionDB example is not premium content, it's only a "No free lunch" example and you can get it for a small fee...

as a start you can read the Google documentation about authentication https://developers.google.com/accounts/docs/OAuth2 and try to convert this into App Inventor
Good luck!

Taifun
Message has been deleted

Severler

unread,
Dec 27, 2014, 11:43:39 AM12/27/14
to mitappinv...@googlegroups.com
Thanks

I do it i use pagetitle for accestoken and i use segment block for refreshT

I use start number 172 and leght number 45 for segment block so ı can get refresh token 

I have litle question about refresh token leght is it always 45?
Reply all
Reply to author
Forward
0 new messages