google-drive-sdk,google-oauth,google-api-php-client , Google Drive help required access to own Drive account

Google Drive help required access to own Drive account


Tag: google-drive-sdk,google-oauth,google-api-php-client

I want to access my own google drive on web page but allow anyone to upload files and restrict download access or show only limited file to user for downloading.

Drive API assumes that I will access another users credentials. But what I want is opposite, anyone can view my files (restricted what to view) but is free to upload. I have google nearly 6+ hours and didn't found any solution

Any Help Appreciated Thanks


You say "Drive API assumes that I will access another users credentials" but this isn't correct. Calls to Drive include an Access Token, and it is that which determines which Drive account the call will access. Drive makes no assumptions about how that Access Token was obtained or which account it refers to.

All of the examples show how an Access Token is obtained for an end user, since that is the more complex flow. Your requirement is very much simpler.

All you need to do is:-

  1. Obtain a refresh token (see How do I authorise a background web app without user intervention? (canonical ?))
  2. Store that refresh token in your PHP application. Make sure it's secure
  3. When you need to access your Drive account, use the refresh token to obtain an access token as described at


How to authenticate a java application for the Google Contacts API?

I've had a java application running for a few years that synced some contacts from some database into the gmail account of a customer. This stopped working a few days ago, presumably because Google stopped supporting the simple username/password authentication. First question: Am I correct in assuming that the only...

Google Drive file download via http

There is a link to Google Drive file accessible to anyone without authentication. Is there any way to download that file using just link and some sort of http client? Most of examples around are relying on Drive API and file IDs, however I'd like to stick with more lightweight...

How to browse files from projects google drive

i have created project in google console with service type credentials. I have downloaded p12 key file, and then wrote sample code for inserting file to test it: <?php require_once 'google-api-php-client/src/Google_Client.php'; require_once 'google-api-php-client/src/contrib/Google_DriveService.php'; require_once "google-api-php-client/src/contrib/Google_Oauth2Service.php"; $scopes = array(''); $accountEmail = 'SECRET'; $accountP12FilePath = './key.p12'; $key = file_get_contents($accountP12FilePath);...

What is the correct mechanism to authenticate to Google in a standalone Python script?

I've got some code that I'm using to extract email address from Gmail contacts into text file. It's a simple Python script that runs in a cron job, and is based on the Python gdata library (currently v2.0.18). As of earlier this month, this no longer works due to Google...

Any way te read an excel file from a Google Sheet?

in my organization we work with Google Apps but we have one file that we need to maintain in Excel due to its complexity. All my other spreadsheets are Google Sheets and a lot of them need to get data from that excel file. So my question is: is there...

Google Analytics Embed API: Display specific account data, not authenticated users

I have this example - Embed API Third Party Visualizations - working locally and on a test server, but I'm unsure of what I need to do to ONLY display our organization's Google Analytics data instead of the user's personal GA account. I created the project and clientID within our...

How to login with another user when using Google for login?

I am using Google login to authenticate user before they login to my website. Here is what I am doing. User comes to my website Click on login button Login with Google account if user pass google authentication, session is set when user click on logout, session is destroyed Basic...

Google SignIn State

I'm trying to build a Google signin button into my website. I'm trying to avoid using their built-in button. The code below works to sign in a user, but I can't figure out how to make my webpage remember that they're signed in when the user refreshes the page, or...

What does “offline” access in OAuth mean?

What exactly does the word "offline" mean with regard to the offline access granted by an OAuth server? Does it mean that the resource server will return data about the user even when the user is logged out of the third-party application or when the user is logged out of...

Pass Comments & Suggested Edits from a Google Document to a Google Sheet

Fellow Stackers. I'm using a Google Apps Script to (a) capture all "Comments" in a Google Document... ...and (b) list them in a column of a Google Sheet... However, I'm wondering if it's possible to... (1) Array "Comments" into individual cells down a column in my Sheet rather than into...

Adding google api client to codeigniter

I want to upload files to google drive using php in codeigniter. First of all i am trying to integrate google api client to codiginator. I have uploaded all the files in to my third_party folder. it look like this I i have created a file called google.php inside my...

Google Drive API 500 null errors when copying

I'm getting this error message (100% of the time) when copying a shared file, using the latest version of php library. And I'm getting the same response via the API explorer: Google_Exception: Error calling POST (500) { "error": { "code": 500, "message": null } } This issue seem...

Google Drive API (GTL) - Create multiple folder paths in order?

I'm using the Google APIs Client Library for Objective-C (GTL) to access the Google Drive API. According to it's Introduction to the Google APIs Client Library for Objective-C, Query execution by the service is inherently asynchronous. Which means when you try to create a path like: root/a/b/c, before you can...

Google Drive API: I have to fetch only files in that folder without trashed files

I am trying to get a list of files in a folder on Google drive using the Google drive API. When I make my request I am getting a list of child elements in that folder including previous deleted files. How do I get only the files that are in...

Gmail API: example of a request to the API

I am trying access the Gmail API with my application. I should have done properly all the setup and I am testing a request to the API, in the specific the request to get the messages as read only. My code: public function gmail_get_messages() { $client = new Google_Client(); $client->setApplicationName("Gmail...

Can one track the usage of a shared resource from google drive

Does anyone here know if you on Google Drive somehow can track if a public shared link to a file have been used? That is, the resource have been downloaded, viewed or otherwise "touched"?...

Providing login_hint option for Google Oauth2 redirect

I'm passing in login_hint=1 option as part of Oauth2 request query string but this doesn't appear when I receive a callback from Google Oauth2 after accepting it. I'm only getting: google/oauth2callback?code=4/vadsdaalijfqwo8fdjqojcxadassddsa# I was expecting 1 (which is user id) to come back as part of callback. How do I make...

How to use token obtained using GoogleAuthUtil class to get user information?

I am building an Android app in which I want to authenticate user using their google account. I am using GoogleAuthUtil class to obtain token from google as shown below protected String fetchToken() throws IOException{ try { return GoogleAuthUtil.getToken(act, email, scope); } catch (GoogleAuthException e) { e.printStackTrace(); } return null;...

Oauth2 using Python 3.4 and Django 1.7

I'm trying to authorize my django application using oauth2 in order to interact with the google content for shopping API. However, I'm experiencing issues with oauth2 along the way. I have oauth2client and google-api-python-client installed. My view is as follows: CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secret.json') FLOW = flow_from_clientsecrets( CLIENT_SECRETS, scope='', redirect_uri='')...

Google Drive revokes my token

I am new to google drive and started with the tutorial quickstart. After numerous attampts I run the program successfully. However I had permission and authorisation problems when I was trying to delete files. Drive service = getDriveService(); service.files().delete("FileId").execute(); So I decide to change the URL in the client_secret.json, From:...

Need clarification on email_verified field of ID Token

I'm using Google's OpenID Connect service to authenticate users. I was considering rejecting all accounts if the email_verified field was false, but I don't see a real world scenario where someone will hit my system with this field set to false. The first time you log in to Google the...

Removing permissions of the extensions

I have an extension that first asks for permissions to access Google Drive files. The extension is almost empty except in the popup I load this js: chrome.identity.getAuthToken({ 'interactive': true }, function(token) { // Use the token. console.log('Request Token') console.log(token) chrome.identity.removeCachedAuthToken( { 'token': token }, function () {}) console.log('Removed token')...

google-apps-script count files in folder

I've had a search but cannot seem to find what I am looking for. I am seeking the code to enable me to do this pseudocode: Count number of files in specific Google Drive folder (by folder Id) If file count is above 'x' do this {other piece of code}...

Google AdEx Seller API doesn't support Service accounts

I want to pull periodic reports via Google Seller API. Is there a way, to login into Seller account without having to go via regular OAuth redirection ?

Can I associate a user's account with an action to the drive API?

We're looking to make a little webapp to manage our week-long nerf war (humans vs zombies to be precise), and we're thinking about how easy it would be to have Google Sheets be our only backend, and our frontend be entirely javascript/html/css. Let's say there's two actions that can be...

access drive with access token

struggling to understand the oauth2 token and refresh token processes ive got this code $url = ''; $data = array('client_id' => 'clientid', 'client_secret' => 'secret','refresh_token' => 'token','grant_type' => 'refresh_token'); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded", 'method' => 'POST', 'approval_prompt'=>'force', 'access_type'=>'offline', 'content' => http_build_query($data), ), ); $context...

How can I insert data (event) into Google Calendar with PHP?

I am trying to insert events into Google Calendar, but I get errors everytime. I've been searching for hours to get answer, but I found nothing for my problem. I tested a lot of examples, without success. I'm new in Google Calendar, and I can't really understand the google api...

Directory sandboxed access for Google Drive / Dropbox API / RemoteStorage apps?

Is there a way to get sandboxed, user-selected directory access on any major file service without first getting read level access to their entire filesystem? There's a lot of talk about "unhosted" static webapps that allow users to access their data from a 3rd party file service (Google Drive, Dropbox,...

Newbie Google Drive API (PHP) confusion - what guide/library to use?

I have a mobile site - from a phone I want visitors to choose a file from Google Drive, and send it to the server that hosts Essentially emulating a simple <input type="file"> file upload as on a desktop. From what I understand the workflow is as follows:...

google Oauth login in https server

I have an meteor web server on Https server say I added this url to the Javascript Origin uri and in redirect uri. On request, it says mismatch uri and asked to put in redirect uri. Adding that gives me an error of Uncaught SecurityError: Blocked a...

Google Calendar API event insert always return 404 “not found” error iOS

I'm tried the calendar insert example from here : No matter which property i use, i always get the 404 "not found" error. Anyone can shed some light on this? Many thanks!!! PUT{YOUR_API_KEY} Content-Type: application/json Request Body : { attendees = ( { email = "[email protected]"; } );...

401 Unauthorized when authentificating with Google for hybrid applications

I want to use native applications and a web server to get refresh tokens to use for some operations (on google drive). Client ids and secrets have been generated for both the native and the web application using the Google developer console. I'm trying to generate authcodes from the native...

What is the preferred method of using Google for sign-in?

Google has a habit of providing multiple means to achieve a goal. And of ditching services when they feel like it. If I would need to implement a "sign-in with Google" authentication feature today, which one should I pick? Google Sign-In or Google+ Sign-In? Or to put it differently: which...

Advanced Drive Services in Addons

I have a Google Script that uses the Advanced Drive API service and am now looking to convert this script into an Add-on. However the Drive API needs to be enabled manually by the user before using the service inside the Apps Script. Is it possible to use the advanced...

Google Drive API VB.NET Parent Folder of a Folder,google-drive-sdk,folder,parent
I am trying to work with Google Drive API with I have seen a lot of post but I am not able to understand how to choose the right folder to add a file. I have a lot of "Backup" folder but, I assume now, I want to add...

Gmail API: How to get access token?

I am testing the Gmail API. So far I have done the following: I have created the project in the Google Developers Console I have enabled the Gmail API. I have created a new Client ID and the client secret. In my PHP script I have installed the PHP Client...

How can I make a copy of a file in Google Drive via Python?

I wrote a short function in Google Apps script that can make a copy of a specific file that is stored on Google Drive. The purpose of it is that this file is a template and every time I want to create a new document for work I make a...

Cannot refresh token from google api OAuth2

Here is my php script RefreshToken.php <?php $url = ''; $post_data = array( 'code' => 'xxxxxxxx', 'client_id' => 'xxxxxxxxxxx', 'client_secret' => 'xxxxxxxxxxxxx', 'redirect_uri' => 'http://localhost/googleapi/AuthenticationCode.php', 'grant_type' => 'authorization_code', ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result =...

Google Drive - How to List all Files in a specified folder

Hi I am stuck here with this situation, I have tried a number of different approaches but I cannot get what I am after. Situation: I have a large number of files in folders hosted on google drive. For instance a single client folder for reports has between 2000-10000 files(this...

How to return RSA key in jwks_uri endpoint for OpenID Connect Discovery

Working on the discovery part of an OpenID Connect provider, I'm a bit confused about how to properly return my public keys. My problem is specifically with the modulus (n) and the exponent (e) values. The initial values of both are: n =...

How to create a Google form programatically with python ?Is it possible to do so by appscript and python interfacing or something like that?

How to create a Google form programatically with python ? Do they provide some api like drive api to do so ? Is it possible to interface python with Google appscript ? Here they are talking about creating a form with a form using app script . Thank you...

Google Drive API every time asking for authentication code

I'm using google drive api to upload a file to google drive using php, but it every time asking me for authentication code fof my application. I have followed the steps given in the URL below My Code: require_once 'src/Google/autoload.php'; $client = new Google_Client(); // Get your credentials from...

Prompt user to enter password - Google OpenID Connect

We are trying to use Google's OpenID Connect for a business web app but are concerned that the user will leave the app open and an unauthorized user will sign-in because the user is still signed into Google so OpenID Connect just let's them right in. We've tried using max_auth_age=0...

401 Unauthorized - Google Drive API,.net,,google-drive-sdk
I'm working with the Google APIs for the first time and I'm having problems trying to download files with the File object "downloadUrl" property. I'm currently using the "Service Account" option with the associated service account email and P12 certificate. However, the URL returned "" returns a 401 - Unauthorized...

Google authentification with “devise” fail

I want to create a GOOGLE authentification in my app. So in set up "omniauth" and "devise" correctly (I think). In my layout folder in "_header.html.erb" view : <% if user_signed_in? %>Signed in as <%= %>. Not you? <%= link_to "Sign out", destroy_user_session_path,:method => :delete %> <% else %>...

Insert file using Google Drive API?

Based on Google Drive API reference guiding how to insert file Files.insert // File's metadata. File body = new File(); body.setTitle(title); body.setDescription(description); body.setMimeType(mimeType); // File's content. fileContent = new; FileContent mediaContent = new FileContent(mimeType, fileContent); try { File file = service.files().insert(body, mediaContent).execute(); // Uncomment the following line to...

How to save my data in a cloud?

I don't know if this is possible, but I would like to save some data of my website, like images and documents in a cloud like dropbox or google drive and I want that these data are available and visible to someone looking my site. is it possible? (My intention...