php - google drive API authorize issue -


I have followed the tutorial on Google Drive, to say that authentication / access token we use to refresh token We continue to do so, so we do not need to be certified / every time we ask to authorize an API call that

code:.

  require_once 'google-api-php-client / src / Google_Client.php'; Need_once 'google-api-php-client / src / contrib / Google_DriveService.php'; $ Client = new Google_Client (); // console $ client- & gt; Get your credentials from setClientId ('Client ID'); $ Client- & gt; Set client SERT ('customer secret'); $ Customer & gt; SetRedirectUri ('url'); $ Customer & gt; SetScopes (array ('https://www.googleapis.com/auth/drive')); $ Customer & gt; SetAccessType ('offline'); $ Service = new Google_DriveService ($ customer); $ AuthUrl = $ client- & gt; CreateAuthUrl (); // Access token $ access to Exchange authorization code token = $ client- & gt; Authenticate (); $ Customer & gt; SetAccessToken ($ accessToken); $ Files = $ service-> File-> List files (); Echo "& lt; east & gt;"; Print_r ($ files);  

This gives me a list of files and folders, but every time I refresh the page that takes me back to the Google authorization page I can save the access token in the database How do I use it, and how to make API calls without user authorization?

Any ideas ??

Thank you,
Aniket

Probably, using this P12 key Server is better to use the server for authentication:

<. P> You can impersonate a user account and all files will be accessed from your server

  $ client_email = '1234567890-a1b2c3d4e5f6g7h8i@developer.gserviceaccount.com'; $ Private_key = file_get_contents ('MyProject.p12'); $ User_to_impersonate = 'user@example.org'; $ Private_key = file_get_contents ($ pkey); // notasecret $ scopes = array ('https://www.googleapis.com/auth/drive'); $ Credits = new \ Google_Auth_AssertionCredentials ($ client_email, $ scope, $ private_key, 'notasecret', // default P12 password 'http://oauth.net/grant_type/jwt/1.0/bearer', // default grant type $ user_to_impersonate ); $ Client = new \ Google_Client (); $ Customer & gt; SetAssertionCredentials ($ credits); If (; getAuth () - & gt; $ Customer & gt ;AccessTokenExpired ()) {$ Customer & gt; GetAuth () - & gt; RefreshTokenWithAssertion (); } $ Service = new \ Google_Service_Drive ($ customer); $ Files = $ service-> File-> List files (); Echo "counting files =". Count ($ files). "& Lt; br & gt;"; Forex Currency ($ item $ item) {echo "title =". $ Item ['title'] "& Lt; br & gt;"; }  

This will give you all the files listed in your Google Drive without any customer user interaction.


Comments