作为实习的一部分,我正在制作一个"品牌检查器",您可以在其中输入新公司名称,它会检查您是否使用了域(.com,.net,.org,.nl),以及Facebook,Twitter和LinkedIn页面是否已被占用。我现在处于LinkedIn部分,我只需要知道该页面是否存在。我不必查看帖子,成员,成员计数或类似的东西,我只需要知道它是否存在。
LinkedIn API 说我可以做到这一点,我只需要授权与 OAuth 的会话 (?)。老实说,我对OAuth一无所知,但有些事情告诉我,必须有另一种方法来检查公司页面或组是否存在。
有没有另一种方法可以在不使用OAuth的情况下检查公司或组是否存在?
谢谢!
这并不难,由于访问令牌的有效期为 60 天,因此您可以手动获取如下所示的令牌:
- 使用
https://bogus.com/linkedin
等虚假redirect_uri
在 https://www.linkedin.com/secure/developer 上注册应用程序,并复制生成的consumer key
并consumer secret
- 输入浏览器栏
https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=<consumer_key>&state=bogus&redirect_uri=https%3A%2F%2Fbogus.com%2Flinkedin
- 登录并接受客户的权限,然后您将被重定向到一个非功能性 URL,例如
https://bogus.com/linkedin?code=<code>
-
将该 URL 中的
code
值复制到以下 CURL 命令中:curl "https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=<code>&redirect_uri=https%3A%2F%2Fbogus.com%2Flinkedin&client_id=<consumer_key>&client_secret=<consumer_secret>"
您的访问令牌将在响应中,如下所示:
{"access_token":"<token>","expires_in":5174190}
然后,您可以拨打如下电话:
curl -H "Authorization: Bearer <token>" "https://api.linkedin.com/v1/company-search?keywords=<name>&format=json"
那么PHP相当于:
$headers = array(
'Authorization: Bearer ' . $token,
'x-li-format: json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
$r = json_decode($response);