Missing required parameter: scope when using $authorizationUrl

1,956 views
Skip to first unread message

Alan Coleman

unread,
Oct 27, 2013, 7:14:33 AM10/27/13
to adwor...@googlegroups.com
 Hello everyone,

I'm successfully generating $authorizationUrl using the code below. However on using that URL I'm receiving the error:

Missing required parameter: scope.

OAUTH2_SCOPE is being declared as a constant in the AdWordsUser class so I'm confused as to why it's not being carried across.

I'm working with the following:

Library: adwords_api_php_4.5.1
Version: v201306

As Always, any ideas would be appreciated.




 function GetOAuth2Credential($user, $callbackUrl) {
       $redirectUri = $callbackUrl;
       $offline = TRUE;
       // Get the authorization URL for the OAuth2 token.
       // Pass in a redirect URL back to the application,
       // Passing true for the second parameter ($offline) will provide us a refresh
       // token which can used be refresh the access token when it expires.
       $OAuth2Handler = $user->GetOAuth2Handler();
       $authorizationUrl = $OAuth2Handler->GetAuthorizationUrl(
      $user->GetOAuth2Info(), $redirectUri, $offline);

   return $authorizationUrl;
}   

 // Create a new user and set the oAuth settings
  $user = new AdWordsUser();
  $user->LogAll();
  $user->SetOAuth2Info(array(
      "client_id" => $clientId,
      "client_secret" => $clientSecret
       ));
 // Generate an authorization URL given the callback URL
        $authUrl = GetOAuth2Credential($user, $callbackUrl);

Paul Matthews (AdWords API Team)

unread,
Oct 29, 2013, 6:49:36 AM10/29/13
to adwor...@googlegroups.com
There doesn't appear to be any issues with the code you're providing.

Can you inspect the OAuth2Handler class to see if it has the scope property set?

var_dump($user->GetOAuth2Handler());

Also, double check that you've not changed the OAUTH2_HANDLER_CLASS specified in the settings.ini.

Regards,

- Paul, AdWords API Team.

Alan Coleman

unread,
Nov 4, 2013, 6:46:41 AM11/4/13
to adwor...@googlegroups.com
 Hi Paul,

Thanks very much for replying.

var_dump($user->GetOAuth2Handler()); Does indeed reveal that the scope variable in SimpleOAuth2Handler is null. 

I've hard coded the variable in Oauth2Handler.php

  public function __construct($server = NULL, $scope = 'https://adwords.google.com/api/adwords/') {
    $this->server = $server;
    $this->scope = $scope;
  }

This seems to work although I'm unsure as to why $scope isn't being picked up elsewhere. Is this an acceptable solution?

Also, the OAUTH2_HANDLER_CLASS specified in the settings.ini. is coded out, is this correct?

Thanks again.

Paul Matthews (AdWords API Team)

unread,
Nov 4, 2013, 7:31:32 AM11/4/13
to adwor...@googlegroups.com
Hi Alan,

This looks as though there's an issue with your settings.ini, please compare to the original settings.ini and confirm the changes are correct. Yes the OAUTH2_HANDLER_CLASS should be commented out as it defaults to the SimpleOAuth2Handler.

The scope should be configured by the AdWordsUser object, from the class constant. Is there a reason why your system wouldn't honor the class constant? Are you extending the AdWordsUser or have you changed the GetDefaultOAuth2Handler implementation?

Regards,

- Paul, AdWords API Team.

Reply all
Reply to author
Forward
0 new messages