AdsUser::ValidateOAuth2Info PHP Method

ValidateOAuth2Info() protected method

Validates that the OAuth2 info is complete.
protected ValidateOAuth2Info ( )
    protected function ValidateOAuth2Info()
    {
        $requiredFields = array('client_id', 'client_secret');
        foreach ($requiredFields as $field) {
            if (empty($this->oauth2Info[$field])) {
                throw new ValidationException($field, null, sprintf('%s is required.', $field));
            }
        }
        if (empty($this->oauth2Info['access_token']) && empty($this->oauth2Info['refresh_token'])) {
            throw new ValidationException('refresh_token', null, 'Either the refresh_token or the access_token is required.');
        }
    }

Usage Example

示例#1
0
 /**
  * Validates the user and throws a validation error if there are any errors.
  * @throws ValidationException if there are any validation errors
  * @access private
  */
 private function ValidateUser()
 {
     if ($this->GetOAuthInfo() != NULL) {
         parent::ValidateOAuthInfo();
     } else {
         if ($this->GetOAuth2Info() != NULL) {
             parent::ValidateOAuth2Info();
         } else {
             if ($this->GetAuthToken() == NULL) {
                 if (!isset($this->email)) {
                     throw new ValidationException('email', NULL, 'email is required and cannot be NULL.');
                 }
                 if (!isset($this->password)) {
                     throw new ValidationException('password', NULL, 'password is required and cannot be NULL.');
                 }
                 // Generate an authToken.
                 $this->RegenerateAuthToken();
             }
         }
     }
     if ($this->GetApplicationName() == NULL) {
         throw new ValidationException('applicationName', NULL, 'applicationName is required and cannot be NULL.');
     }
 }
All Usage Examples Of AdsUser::ValidateOAuth2Info