
/how-to-fix-a-400-bad-request-error-2617988-70ec8d87146e462cae353c32d0dcb64a.png)

4/0AX4XfWgU3p6QqHeogZ7NitClTYDt3Tf_bv-A1kI4UoEm0CzpHiXrpD8TEnLUxta-SKFLlA&scope= It is this code that you add to your application. If you look at the url bar within that string returned is a code. You will see a 400 error in the browser window when it is complete ignore this. $accessToken = $client->fetchAccessTokenWithAuthCode($authCode) Ĭopy the authorization link and place it in any web browser. Exchange authorization code for an access token. Printf("Open the following link in your browser:\n%s\n", $authUrl) The section of the code which handles the authorization for us is as follows $authUrl = $client->createAuthUrl() Go to the oauth screen and set it to production and the refresh token will stop expiring. Warning refresh tokens will expire after seven days while your project is set to testing in google cloud console. Then when the app runs again it will be able to use the refresh token to request a new access token in order to access your google drive account. After you have authorized the app once a refresh token will be stored there.

This code is designed to store the user authorization within a file called token.json. I recommend checking for the most recent version number on the php packages repository composer require google/apiclient:^2.12.1 Authorization Instructions for this can be found on the Google api PHP client library README. You will need to install the php client library this can be done using composer. This can be created on google cloud console make sure to create native credentials. The first thing you will need is to create a credetials.json file.
