我们如何正确格式化 LinkedIn post 对字段选择器(包含冒号和括号)的请求?
How do we correctly format a LinkedIn post request for a field selector (one containing colons and parentheses)?
我成功地使用 LinkedIn People Profile API 为用户访问,在用户授予权限后,在将身份验证代码交换为 60 天访问令牌后,我可以 POST 请求和 return 各种配置文件数据。
我正在根据 https://developer.linkedin.com/documents/code-samples 中的示例代码使用 PHP。
到目前为止,我的所有请求都已成功。例如,这个有效:
$user = fetch('GET', '/v1/people/~:(first-name,last-name,num-connections,headline,industry,specialties,summary,public-profile-url,email-address,interests,publications,languages,skills,three-current-positions,phone-numbers,main-address,twitter-accounts,primary-twitter-account,educations,num-recommenders)');
fetch 函数(来自上面提到的示例代码)构建 POST 请求,使请求和 returns $user 对象填充所有数据。
但是,如果我添加以下两个定义为字段选择器的字段:
location:(name),location:(country:(code))
所以上面的语句变成:
$user = fetch('GET', '/v1/people/~:(first-name,last-name,location:(name),location:(country:(code)),num-connections,headline,industry,specialties,summary,public-profile-url,email-address,interests,publications,languages,skills,three-current-positions,phone-numbers,main-address,twitter-accounts,primary-twitter-account,educations,num-recommenders)');
return根本没有从 fetch 中编辑任何内容。
要测试,在 fetch 函数中,紧跟在:
$response = file_get_contents($url, false, $context);
声明我添加了声明:
print 'response: ' . print_r($response, true);
并且在 returned 页面中它只显示 "response: " 一个空值 - 甚至没有错误消息。
但是如果我删除两个字段选择器字段,请求工作正常并且所有信息都是 returned。
我猜我需要以某种不同的格式指定这两个字段,但我无法从文档和示例中弄清楚该格式可能是什么,所以我希望这里有人可以给我一个提示。
我也很好奇为什么 returned 没有错误 - 只是一个空白值。错误消息对调试很有用。
谢谢,
道格
应聚合子字段,例如:
location:(name,country:(code))
您的查询中应该只出现一次 location
。
如果有疑问,请检查您在 LinkedIn REST-console 中的查询,对于您的查询,我得到:
<?xml version="1.0" encoding="UTF-8"?>
<error>
<status>400</status>
<timestamp>1422276799156</timestamp>
<request-id>XMQPA0BXDC</request-id>
<error-code>0</error-code>
<message>Duplicate field {location} in inline filter {(first-name,last-name,location:(name),location:(country:(code)),num-connections,headline,industry,specialties,summary,public-profile-url,email-address,interests,publications,languages,skills,three-current-positions,phone-numbers,main-address,twitter-accounts,primary-twitter-account,educations,num-recommenders))}</message>
</error>
这清楚地表明了问题。
我成功地使用 LinkedIn People Profile API 为用户访问,在用户授予权限后,在将身份验证代码交换为 60 天访问令牌后,我可以 POST 请求和 return 各种配置文件数据。
我正在根据 https://developer.linkedin.com/documents/code-samples 中的示例代码使用 PHP。
到目前为止,我的所有请求都已成功。例如,这个有效:
$user = fetch('GET', '/v1/people/~:(first-name,last-name,num-connections,headline,industry,specialties,summary,public-profile-url,email-address,interests,publications,languages,skills,three-current-positions,phone-numbers,main-address,twitter-accounts,primary-twitter-account,educations,num-recommenders)');
fetch 函数(来自上面提到的示例代码)构建 POST 请求,使请求和 returns $user 对象填充所有数据。
但是,如果我添加以下两个定义为字段选择器的字段:
location:(name),location:(country:(code))
所以上面的语句变成:
$user = fetch('GET', '/v1/people/~:(first-name,last-name,location:(name),location:(country:(code)),num-connections,headline,industry,specialties,summary,public-profile-url,email-address,interests,publications,languages,skills,three-current-positions,phone-numbers,main-address,twitter-accounts,primary-twitter-account,educations,num-recommenders)');
return根本没有从 fetch 中编辑任何内容。
要测试,在 fetch 函数中,紧跟在:
$response = file_get_contents($url, false, $context);
声明我添加了声明:
print 'response: ' . print_r($response, true);
并且在 returned 页面中它只显示 "response: " 一个空值 - 甚至没有错误消息。
但是如果我删除两个字段选择器字段,请求工作正常并且所有信息都是 returned。
我猜我需要以某种不同的格式指定这两个字段,但我无法从文档和示例中弄清楚该格式可能是什么,所以我希望这里有人可以给我一个提示。
我也很好奇为什么 returned 没有错误 - 只是一个空白值。错误消息对调试很有用。
谢谢,
道格
应聚合子字段,例如:
location:(name,country:(code))
您的查询中应该只出现一次 location
。
如果有疑问,请检查您在 LinkedIn REST-console 中的查询,对于您的查询,我得到:
<?xml version="1.0" encoding="UTF-8"?>
<error>
<status>400</status>
<timestamp>1422276799156</timestamp>
<request-id>XMQPA0BXDC</request-id>
<error-code>0</error-code>
<message>Duplicate field {location} in inline filter {(first-name,last-name,location:(name),location:(country:(code)),num-connections,headline,industry,specialties,summary,public-profile-url,email-address,interests,publications,languages,skills,three-current-positions,phone-numbers,main-address,twitter-accounts,primary-twitter-account,educations,num-recommenders))}</message>
</error>
这清楚地表明了问题。