Can't sign into OAuth for business management

61 views
Skip to first unread message

Wes Kay

unread,
Jun 2, 2021, 1:25:46 AM6/2/21
to Google's Campaign Manager 360 API Forum
Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:
{
  "error": "invalid_grant",
  "error_description": "Bad Request"
}

In my web app I was able to get to the grant permissions for the business scope but now I just keep getting this invalid_grant error. I synced my clock to server time, and I cannot figure this out at all. Installing the `"google/apiclient": "^2.7"` composer package, 

index.php:
```
$credentials = __DIR__ . '/client_secrets.json';


$client = new Google\Client();
$guzzleClient = new \GuzzleHttp\Client(array( 'curl' => array( CURLOPT_SSL_VERIFYPEER => false, ), ));
$client->setHttpClient($guzzleClient);
$client->setAuthConfig($credentials);
$client->setAccessType("offline");
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client->setRedirectUri($redirect_uri);

$my_business_account = new Google_Service_MyBusinessAccountManagement($client);
if (isset($_GET['logout'])) { // logout: destroy token
    unset($_SESSION['token']);
  die('Logged out.');
}

if (isset($_GET['code'])) { // get auth code, get the token and store it in session
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
}


if (isset($_SESSION['token'])) { // get token and configure client
    $token = $_SESSION['token'];
    $client->setAccessToken($token);
}

if (!$client->getAccessToken()) { // auth call 
    $authUrl = $client->createAuthUrl();
    header("Location: ".$authUrl);
    die;
}
```
client_secrets.json:
```
{
    "web": {
        "client_id": "1xxxxxxx.apps.googleusercontent.com",
        "project_id": "myid",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "mysercet",
        "redirect_uris": [
        ],
        "javascript_origins": [
            "http://localhost:8000"
        ]
    }
}
```
Could it be the origin of my redirect? 

Wes Kay

unread,
Jun 2, 2021, 3:03:18 AM6/2/21
to Google's Campaign Manager 360 API Forum
I solved the issue, it was an issue with how it was handling the token. 

DCM API (DoubleClick Campaign Mgr)

unread,
Jun 2, 2021, 4:38:01 AM6/2/21
to keeling...@gmail.com, google-doubleclick-...@googlegroups.com

Hi Wes,

 

I'm glad to hear you fix it on your end.

 

Feel free to come back to us when you have issues regarding DCM API response.

Regards,

Google Logo
Michael Angelo Legaspi
DCM API Team
 


ref:_00D1U1174p._5004Q2HzWQx:ref
Reply all
Reply to author
Forward
0 new messages