php - LinkedIn Share API 'ugcPosts' 响应来自 PHP(Wordpress)的 504 网关超时
问题描述
我正在使用 wordpress 将我的帖子分享到linkedIn。为此,我使用https://api.linkedin.com/v2/ugcPosts API。但是这个 API 响应返回 504 网关超时。
在上一步中,当我调用另一个 API 来获取访问令牌时,它很容易获得了访问令牌。但是当我想使用 ucPosts POST api 请求创建共享时,它会提供网关超时。我在这里请求的代码。
请任何人帮助我。
尝试从 localhost apache 服务器(PHP,wordpress)
$params = '{
"author" : "urn:li:person:'.$linkedInAppCredentials->get_user_URN().'",
"lifecycleState" : "PUBLISHED",
"specificContent" : {
"com.linkedin.ugc.ShareContent" : {
"shareCommentary" : {
"text" : "'.$message.'"
},
"shareMediaCategory" : "NONE"
}},
"visibility" :"PUBLIC"
}';
$headers = '{
"Content-Type": "application/json",
"X-Restli-Protocol-Version": "2.0.0",
"x-li-format": "json",
"Connection": "Keep-Alive",
"Authorization": "Bearer '.$linkedInAppCredentials->getAccessToken().'"
}';
$requestedUrl = "https://api.linkedin.com/v2/ugcPosts?oauth2_access_token=".$this->getAccessToken();
$requestBody = array(
'headers' => $header,
'timeout' => 3600,
'body' => $params
);
$result = wp_remote_post($requestedUrl, $requestBody);
响应:[body] => {"message":"Request timed out","status":504} [response] => Array ([code] => 504 [message] => Gateway Timeout)
解决方案
请求超时可能是因为 LinkedIn 无法解析请求正文。因此,将 requestBody 转换为 JSON 字符串可能是个好主意。提供正确的 JSON 输入对我有用,我遇到了同样的问题。
正如另一个人所发生的那样: https ://stackoverflow.com/a/56786205/12578136
推荐阅读
- javascript - 通过角度编程打开上传对话框
- ionic-framework - 如何使用后端 PHP 在 ionic 4/5 中上传图像?
- angular-material - Mat Paginator 不适用于材料表上的 FormArray
- javascript - 按属性过滤对象数组并获取与其关联的 storeID
- python - 为什么我的烧瓶模板只扩展其包含之一?
- flutter - Flutter 侧边导航栏小部件
- sql-server - VB.NET - SQL Server 查询失败并显示“已经有一个打开的数据读取器关联”
- ruby-on-rails - 多租户应用程序的 Stripe Connect 重定向 uri 问题
- sql-server - SQL Server 在 Docker 容器中找不到备份文件
- android - 使用 getStream 的聊天和提要应用程序,具有自定义 UI