php - Bing Ads sdk V12:错误代码 105,凭据无效(客户管理)
问题描述
我在执行“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 函数,结果相同。
有任何想法吗?谢谢你的时间。
解决方案
以下是一些值得探索的想法:
- 您能否使用这些凭据登录 Bing Ads Web 应用程序,即该用户是否有权访问 Bing Ads 帐户?
- OAuthTokens->AccessToken 是设置还是为空,例如,尝试 var_dump($authentication)。
- 尝试直接在 auth 对象中刷新令牌,例如,请参阅此示例。
记录 SOAP 请求和响应以查看是否在 GetUser 调用中设置了 AuthenticationToken,例如,在 GetUser 调用之后立即打印最后一个请求/响应:
print $GLOBALS['Proxy']->GetService()->__getLastRequest()."\n"; print $GLOBALS['Proxy']->GetService()->__getLastResponse()."\n";
否则,要确认凭据,您可能需要直接联系Bing Ads 支持。
我希望这有帮助!
推荐阅读
- elasticsearch - 在 RapidMiner 中使用弹性搜索
- winapi - Win32Api 窗口移动
- github - 图片未嵌入到 GitHub 的 md 文件中
- python - 在我自己实现的 kNN 算法中找到训练和测试错误
- python - 仅为一个应用程序修改标准类
- r - 无法配置 R 语言“需要 bzip2 库和标头”
- apache-spark - 如何将 Spark DataFrame 插入 Hive 内部表而不重复?
- java - 如何在最新的 Android Studio 3.2 中打开 Android 设备监视器
- powershell - 使用 Powershell 在文件中查找 CRLF
- java - Java ExecutorService 运行线程两次