This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* curl_easy_setopt(handle, option, parameter): tells libcurl how to behave | |
/* specify URL to get */ | |
curl_easy_setopt(curl_handle, CURLOPT_URL, "https://accounts.google.com/o/oauth2/device/code"); | |
char data[255]; | |
strcat(data, "client_id="); | |
strcat(data, client_id); | |
strcat(data, "&scopescope=https://www.googleapis.com/auth/drive.file"); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(void) | |
{ | |
CURL *curl_handle; | |
CURLcode res; | |
struct MemoryStruct chunk; | |
chunk.memory = malloc(1); /* will be grown as needed by the realloc above */ | |
chunk.size = 0; /* no data at this point */ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char * client_id = "YOUR_CLIENT_ID"; | |
char * client_secret = "YOUR_CLIENT_SECRET"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"device_code" : "4/4-GMMhmHCXhWEzkobqIHGG_EnNYYsAkukHspeYUk9E8", | |
"user_code" : "GQVQ-JKEC", | |
"expires_in" : 1800, | |
"interval" : 5, | |
"verification_url" : "https://www.google.com/device" | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char user_code[255]; | |
char device_code[255]; | |
/* check for errors */ | |
if(res != CURLE_OK) { | |
fprintf(stderr, "curl_easy_perform() failed: %s\n", /* stderr: default destination for error messages */ | |
curl_easy_strerror(res)); /* returns a string describing the error code */ | |
} | |
else { | |
/* Now, our chunk.memory points to a memory block that is chunk.size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printf("Enter below code on 'https://www.google.com/device' :\n"); | |
printf("%s\n", user_code); | |
/* Instruct user to press `Enter` when finish verification process */ | |
printf("Press enter when finish\n"); | |
/* When detect a new line, continue */ | |
while(getchar()!= '\n'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chunk.memory = malloc(1); | |
chunk.size = 0; | |
curl_easy_setopt(curl_handle, CURLOPT_URL, "https://www.googleapis.com/oauth2/v4/token"); | |
char url[300]; | |
strcat(url, "client_id="); | |
strcat(url, client_id); | |
strcat(url, "&client_secret="); | |
strcat(url, client_secret); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"access_token":"1/fFAGRNJru1FTz70BzhT3Zg", | |
"expires_in":3920, | |
"token_type":"Bearer", | |
"refresh_token":"1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char access_token[255]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char access_token[255]; | |
if(res != CURLE_OK){ | |
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); | |
} | |
else{ | |
char *expiresin_result2 = strstr(chunk.memory, "\"expires_in"); | |
int expiresin_position2 = (int)(expiresin_result2 - chunk.memory); | |
char *accesstoken_result = strstr(chunk.memory, "\"access_token"); |