我在执行“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();
}
这是 Authenticate 调用 getUser Function () 的函数
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 函数与文档中 PHP“代码语法”部分中的函数相同。我正在使用带有自己凭据的生产环境。我已经检查了我的开发者令牌和所有相应的权限(这似乎是正确的)。每次尝试执行该请求时,我都会更新我的令牌。我设置请求的方式有什么问题吗?如果问题是关于令牌的,有没有办法检查它是否正确?我准确地说,我也尝试过getAccount 函数,结果相同。
有任何想法吗?谢谢你的时间。