Bing Ads SDK V12:错误代码105,无效的凭据(客户管理)

时间:2018-11-16 09:16:23

标签: php bing-ads-api

我在执行“ GetUser”请求时遇到有关错误代码105(消息:“身份验证失败。提供的凭据无效或帐户无效”)的问题。我已经知道,这是由于目标环境使用了错误的访问令牌(AuthenticationToken标头元素)或开发人员令牌。因此,这必须与我设置凭据(或凭据)的方式有关。这是我的代码:

public function getAuthorization()
{
    $result = AuthController::getRefreshToken(); //get The refresh token, update it if necessary
    AuthController::WriteOAuthRefreshToken($result); //stock the refresh token

    $authentication = (new OAuthWebAuthCodeGrant())
            ->withEnvironment(AuthController::ApiEnvironment) //production
            ->withClientSecret(AuthController::ClientSecret)
            ->withClientId(AuthController::ClientId)
            ->withOAuthTokens(
    (new OAuthTokens())
            ->withAccessToken(json_decode($result, true)["access_token"])
            ->withRefreshToken(json_decode($result, true)["refresh_token"])
            ->withAccessTokenExpiresInSeconds(3600))
        ->withRedirectUri(AuthController::RedirectUri)
        ->withState(rand(0,999999999));

    $GLOBALS['AuthorizationData'] = (new AuthorizationData())
        ->withAuthentication($authentication)
        ->withDeveloperToken(AuthController::DeveloperToken);

    AuthController::Authenticate();
}

这是用于验证身份的函数,该函数调用getUser函数()

static function Authenticate()
{
    // Authenticate for Bing Ads services with a Microsoft Account. Perform a $GLOBALS['AuthorizationData']->Authentication->RequestOAuthTokensByRefreshToken($refreshToken);
    AuthController::AuthenticateWithOAuth();

    $GLOBALS['CustomerManagementProxy'] = new ServiceClient(
        ServiceClientType::CustomerManagementVersion12,
        $GLOBALS['AuthorizationData'],
        AuthController::ApiEnvironment);
    $GLOBALS['CustomerManagementProxy']->SetAuthorizationData($GLOBALS['AuthorizationData']);

    // Here is the problem
    $user = AuthController::GetUser(null, true)->User;
}

我当前使用的getUser函数与documentation的php“代码语法”部分的函数相同。 我使用具有自己的凭据的生产环境。我已经检查了我的开发人员令牌和所有代理权限(似乎正确)。每次尝试执行此请求时,我都会更新令牌。 我设置请求的方式是否有问题? 如果问题出在令牌上,是否有办法检查它是否正确? 我精确地说,我也曾尝试使用getAccount function获得相同的结果。

有什么想法吗?感谢您的宝贵时间。

1 个答案:

答案 0 :(得分:1)

这里有一些想法可供探索:

  1. 您可以使用这些凭据登录Bing Ads web application,即该用户是否有权访问Bing Ads帐户?
  2. OAuthTokens-> AccessToken是否已设置或为空,例如,尝试var_dump($ authentication)。
  3. 尝试直接在auth对象中刷新令牌,例如,请参见this sample
  4. 记录SOAP请求和响应,以查看是否在GetUser调用中设置了AuthenticationToken,例如,在GetUser调用之后立即打印最后一个请求/响应:

    print $GLOBALS['Proxy']->GetService()->__getLastRequest()."\n";
    print $GLOBALS['Proxy']->GetService()->__getLastResponse()."\n";
    

否则,要确认凭据,您可能需要直接联系Bing Ads support

我希望这会有所帮助!

相关问题