Jump to content

API Command (Google)


Recommended Posts

Hi,
Can anyone give me an idea how a command\function needs to look like for using this command
https://developers.google.com/drive/v2/reference/files/touch
If It will be used  to touch a file in my Google drive account say for every 5 seconds with a REST API key from my side, And make it work so on the other side where the file's date is to be acquired (and (?) How can it be compared accordingly to the servers time to see when it was last modified like if  =< 5 sseconds then ..)
I need this to have some way to communicate with the client's side, to tell if my side is reachable, so if my side didn't touch the given file for over 10 seconds, that means that my computer is off due to power failure or something like that
If this first verification passes then I can proceed the communication through emailing 
I tried to look in to TCP server client examples but didn't manage to get the port forwarding to work which stopped my progress .Etc (no experience ..) so I was thinking this method may suit my needs and will be more secure anyways
Thanks

Edited by Deye
Link to comment
Share on other sites

yes,  I already created OAuth 2.0 client IDs  even have the JSON file created and downloaded if needed 

and I have the file's ID let me know what else is needed

Thanks again

Edited by Deye
Link to comment
Share on other sites

21 hours ago, Deye said:

yes,  I already created OAuth 2.0 client IDs  even have the JSON file created and downloaded if needed 

and I have the file's ID let me know what else is needed

Thanks again

@Deye download this udf https://github.com/inververs/googletoken

This is example with  OAuth 2.0 client ID. But it is better for you to make a service account

have no google drive. Therefore, I can not say what the result will be.

Set your own json file and file id

#include '_googletoken.au3'
$client_json_file = 'client_secret_878378520961-hehpvlick1fkk1f24f1kbhqnl4vep6so.apps.googleusercontent.com.json'
_googleapis_setupDesktopOAuth2FromFile($client_json_file)
_googleapis_setScope('https://www.googleapis.com/auth/drive')
$sAccessToken = _googleapis_getToken()
MsgBox(0, 'Token', $sAccessToken)
If Not $sAccessToken Then Exit

$sFileId = 'enter here fileid'
$sURL = 'https://www.googleapis.com/drive/v2/files/' & $sFileId & '/touch'
$sHead = 'Authorization=' & 'Bearer ' & $sAccessToken
$sResponse = __googleapis_request('POST', $sURL, '', $sHead)
MsgBox(0, 'Response', $sResponse)
Edited by Inververs
Link to comment
Share on other sites

 Sorry, My bad I downloaded instead of coping the files contents 
 
 So I Just tested this out:
 I see it will bring me to the Google choose account page, meaning I need to approve a token each time I run the script, is there anyway around this ?
 
 anyhow with my current test the file isn't seen as touched in the activity panel, will look into how to configure the Service account ..
 
 Thanks again

Edited by Deye
Link to comment
Share on other sites

16 minutes ago, Deye said:

I see it will bring me to the Google choose account page, meaning I need to approve a token each time I run the script, is there anyway around this ?

It's strange that you need to confirm the token every start. With this authorization method, the token will be valid for an hour, then it will be updated via a refresh token and only after Google refuses to accept the refresh token, it will again require permission.

But if you work with your account, then you need to do the service key. Then Google will not ask for confirmation at all.

When I first made a request to 'https://www.googleapis.com/drive/v2/files/' & $sFileId & '/touch'  Google asked me to further customize  my application to work with GoogleDrive.

Edited by Inververs
Link to comment
Share on other sites

Edit: keep you posted ..

 Sorry if my responses are delayed my router keeps hanging up my connection, needs to be replaced by my ISP tomorrow ..

Edit: 

This time I used _googleapis_setupServiceOAuth2FromFile($client_json_file) ;service key
 And changed the $client_json_file reference but it seems the AccessToken isn't getting acquired
 will be back to this later, maybe I missed something ..
 Thanks again for sharing this wonderful UDF

Edited by Deye
Link to comment
Share on other sites

How it works in my account

#include 'C:\AutoIt\googletoken\_googletoken.au3'

$service_json_file = 'saaaass-33d6b60d19d1.json'
_googleapis_setupServiceOAuth2FromFile($service_json_file)

_googleapis_setScope('https://www.googleapis.com/auth/drive')
$sAccessToken = _googleapis_getToken()

$sFileId = '0ByJi1lVsD3aNMVZybUNocHlaa1k'
$sURL = 'https://www.googleapis.com/drive/v2/files/' & $sFileId & '/touch'
$sHead = 'Authorization=' & 'Bearer ' & $sAccessToken
$sResponse = __googleapis_request('POST', $sURL, '', $sHead)
ConsoleWrite($sResponse & @CRLF)
MsgBox(0, 'Response', $sResponse)
{
 "kind": "drive#file",
 "id": "0ByJi1lVsD3aNMVZybUNocHlaa1k",
 "etag": "\"dUcwyQ6hN8QZTeM4-DHEZmgLfsU/MTUwMDI5MDExNTQ1MA\"",
 "selfLink": "https://www.googleapis.com/drive/v2/files/0ByJi1lVsD3aNMVZybUNocHlaa1k",
 "webContentLink": "https://drive.google.com/uc?id=0ByJi1lVsD3aNMVZybUNocHlaa1k&export=download",
 "alternateLink": "https://drive.google.com/file/d/0ByJi1lVsD3aNMVZybUNocHlaa1k/view?usp=drivesdk",
 "embedLink": "https://drive.google.com/file/d/0ByJi1lVsD3aNMVZybUNocHlaa1k/preview?usp=drivesdk",
 "iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/application/octet-stream",
 "title": "Nothhing.au3",
 "mimeType": "application/octet-stream",
 "labels": {
  "starred": false,
  "hidden": true,
  "trashed": false,
  "restricted": false,
  "viewed": true
 },
 "createdDate": "2012-06-10T15:10:54.871Z",
 "modifiedDate": "2017-07-17T11:15:15.450Z",
 "modifiedByMeDate": "2017-07-17T11:15:15.450Z",
 "lastViewedByMeDate": "2017-07-17T11:15:27.029Z",
 "markedViewedByMeDate": "1970-01-01T00:00:00.000Z",
 "version": "29214",
 "parents": [
  {
   "kind": "drive#parentReference",
   "id": "0ByJi1lVsD3aNa2tSN25acWNaajA",
   "selfLink": "https://www.googleapis.com/drive/v2/files/0ByJi1lVsD3aNMVZybUNocHlaa1k/parents/0ByJi1lVsD3aNa2tSN25acWNaajA",
   "parentLink": "https://www.googleapis.com/drive/v2/files/0ByJi1lVsD3aNa2tSN25acWNaajA",
   "isRoot": false
  }
 ],
 "downloadUrl": "https://doc-0c-4s-docs.googleusercontent.com/docs/securesc/a3dnmh0b370lmkfcj5cn6h7cs32bueo7/t2g77uuf0pk5bdr4m8uqctctjnri359p/1500285600000/03966103873089652193/03966103873089652193/0ByJi1lVsD3aNMVZybUNocHlaa1k?e=download&gd=true",
 "userPermission": {
  "kind": "drive#permission",
  "etag": "\"dUcwyQ6hN8QZTeM4-DHEZmgLfsU/lAILIw_X_2WHGaSLGP8HDNI4aNI\"",
  "id": "me",
  "selfLink": "https://www.googleapis.com/drive/v2/files/0ByJi1lVsD3aNMVZybUNocHlaa1k/permissions/me",
  "role": "owner",
  "type": "user"
 },
 "originalFilename": "Nothhing.au3",
 "fileExtension": "au3",
 "md5Checksum": "fac403b6e6831b9c079f8cb4632a94e2",
 "fileSize": "463",
 "quotaBytesUsed": "463",
 "ownerNames": [
  "#############"
 ],
 "owners": [
  {
   "kind": "drive#user",
   "displayName": "#############",
   "isAuthenticatedUser": true,
   "permissionId": "03966103873089652193",
   "emailAddress": "#############"
  }
 ],
 "lastModifyingUserName": "#############",
 "lastModifyingUser": {
  "kind": "drive#user",
  "displayName": "#############",
  "isAuthenticatedUser": true,
  "permissionId": "03966103873089652193",
  "emailAddress": "#############"
 },
 "capabilities": {
  "canCopy": true,
  "canEdit": true
 },
 "editable": true,
 "copyable": true,
 "writersCanShare": true,
 "shared": false,
 "explicitlyTrashed": false,
 "appDataContents": false,
 "headRevisionId": "0ByJi1lVsD3aNcVNXeCtnSHlvN0xLNllxdzF2Mzl4Z0RoalRZPQ",
 "spaces": [
  "drive"
 ]
}

 

Edited by Inververs
Link to comment
Share on other sites

  Sorry, I had to jump out
  just tried, not sure why I keep getting this error
 

 "_googletoken.au3" (1004) : ==> The requested action with this object has failed.:
$oHttp.SetRequestHeader($head, $default_headers.item($head))

Edit: NM, I recreated the service account, now I need to check why the AccessToken isn't getting acquired
Will do some more test, not an intuitive setup as thought it would be  

Edited by Deye
Link to comment
Share on other sites

If you get COM errors, such as 

The requested action with this object has failed

This means that the version of the autoit does not fit. See bug tracker If you are interested why.

Ok, it look like you dont know how to check errors. Lets try:

#include '_googletoken.au3'

$service_json_file = 'CardRegistration-33d6b60d19d1.json'
_googleapis_setupServiceOAuth2FromFile($service_json_file)
If @error Then Exit MsgBox(16, '_googleapis_setupServiceOAuth2FromFile', @error)

_googleapis_setScope('https://www.googleapis.com/auth/drive')
If @error Then Exit MsgBox(16, '_googleapis_setScope', @error)

$sAccessToken = _googleapis_getToken()
If @error Then Exit MsgBox(16, '_googleapis_getToken', @error)


$sFileId = '0ByJi1lVsD3aNMVZybUNocHlaa1k'
$sURL = 'https://www.googleapis.com/drive/v2/files/' & $sFileId & '/touch'
$sHead = 'Authorization=' & 'Bearer ' & $sAccessToken
$sResponse = __googleapis_request('POST', $sURL, '', $sHead)
If @error Then Exit MsgBox(16, '__googleapis_request', @error)

MsgBox(0, 'Response', $sResponse)

 

Edited by Inververs
Link to comment
Share on other sites

it goes strait to

_googletoken.au3" (1004) : ==> The requested action with this object has failed.:
$oHttp.SetRequestHeader($head, $default_headers.item($head))
$oHttp^ ERROR

if I move .json to another place i Get error 1 _googleapis_setupServiceOAuth2FromFile

Edited by Deye
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...