Fra*_*ani 6 rest get postman linkedin-api
It's not easy to use the official LinkedIn API and I cannot find a valid documentation.
Following the official documentation I created a new application in order to obtain the Client ID and Client Secret
When I now make a POST call through Postman to https://www.linkedin.com/oauth/v2/accessToken this is what I obtain:
{
"error": "invalid_grant_type",
"error_description": "The passed in grant_type is invalid"
}
Run Code Online (Sandbox Code Playgroud)
Where am I wrong?
EDIT AFTER HELP FROM @Amit Singh
Thanks to @AmitSingh I was able to create 2 different applications, the test with the Client Credentials flow gave me as a result an error retrieving the token:
{
"error": "access_denied",
"error_description": "This application is not allowed to create application tokens"
}
Run Code Online (Sandbox Code Playgroud)
When I try to use the LinkedIn 3-legged workflow I receive Unauthorized
EDIT 3: GETTING THERE THROUGH POSTMAN
I now see that I can ask Postman to do the job, however when I press on Get New Access Token
it opens an error page. I believe the error might be in these 4 elements:
Token name
: maybe I have to give a special token name?Auth URL
: I set https://www.getpostman.com/oauth2/callback
as explained here but maybe I have to set something else?Access Token URL
: I left it blank, maybe I have to put something here?State
: I set a random string like Hello123Boy
but maybe I have to put something else. Maybe is too long. Maybe is too short. Maybe it has to contain symbols, etc... ?...Also, in the guide you linked it says that the applicatoin needs to have:
mine has nothing:
Being recently created is still under review. It says it can take up to 90 days. Is that true?
4th EDIT: I WANT TO BELIEVE!
Here we are, at least now I'm getting the error: Bummer, something went wrong. The redirect_uri does not match the registered value
. This is amazing: finally an error that says where the problem is!
On the app the, on the Products tab, I choose Sign In with LinkedIn
. As
Authorized redirect URLs for your app I set https://www.getpostman.com/oauth2/callback
In Postman I setup Auth URL
and Access Token URL
as you said:
Ami*_*ngh 11
LinkedIn 提供 2 种不同的凭证工作流程。
“授予类型”是指您在 OAuth 工作流程中获取访问令牌的方式。
支持多种资助类型。他们之中有一些是:
客户端凭据- 当您想要访问自己的资源而不是任何其他用户时使用
授权代码- 当应用程序想要访问客户端的数据时使用
刷新令牌- 将过期的访问令牌交换为有效的访问令牌,用于避免用户重复参与
密码- 当应用程序和用户之间存在高度信任时使用,例如 LinkedIn 移动应用程序,您提供用户名和密码
client_credentials
。Content-Type
请记住为 OAuth 中的所有 POST 请求设置application/x-www-form-urlencoded
。创建一个应用程序并获取您的客户端 ID 和客户端密钥。步骤如上面链接的相应文档所示。假设他们有价值观 -<client_id>
和<client_secret>
。
将所需的 POST 发送至https://www.linkedin.com/oauth/v2/accessToken
并包含以下信息。
参数
grant_type : client_credentials
client_id : <client_id>
client_secret : <client_secret>
Run Code Online (Sandbox Code Playgroud)
注意: client_credentials
是要输入的文字文本grant_type
。
响应将返回一个 JSON 对象,其中包含您的访问令牌及其过期时间(以秒为单位)。
回复
{
"access_token" : <access_token>,
"expires_in" : "1800"
}
Run Code Online (Sandbox Code Playgroud)
使用<access_token>
步骤2中获取的API发出请求。
例子
Request URL: https://www.linkedin.com/v2/jobs
Request type: GET
Parameters
Authorization: Bearer <access_token>
Run Code Online (Sandbox Code Playgroud)
授予类型将为授权代码 - code
,因为您想要访问用户的数据。
您Content-Type
应该适用application/x-www-form-urlencoded
于 OAuth 中的所有 POST 请求。
重定向 URL是 OAuth 服务器在成功授权后将重定向用户的 URL。
#
.创建应用程序并提供重定向 URL(如果尚未提供)。检查文档以获取有关如何执行此操作的信息。
获取您的客户端 ID 和客户端密钥。假设值为<client_id>
和<client_secret>
。
生成一个随机的、难以猜测的字符串。假设它是<random-string>
.
选择步骤 1 中提供的重定向 URL 之一,您希望用户在授权后重定向到该 URL。假设是这样<redirect_uri>
。
假设您想要:
r_emailaddress
- 获取他的电子邮件地址w_member_social
- 代表用户发布、评论和点赞帖子。这些被称为“权限范围”,即用户对您进行身份验证的权限。在请求中发送这些范围时,它们应该进行 URL 编码并以空格分隔。在这个特定的例子中,我们的范围将是scope: r_emailaddress%20w_member_social
。我们对上面提到的范围进行了 URL 编码。
添加有关 Microsoft 文档范围的更多信息:
您的应用程序可用的范围取决于您的应用程序可以访问哪些产品或合作伙伴计划。您的应用程序的“身份验证”选项卡将显示当前可用的范围。您可以在“产品”选项卡下申请新产品。如果获得批准,您的应用程序将可以访问新的范围。
发送包含以下信息的 POST 请求https://www.linkedin.com/oauth/v2/authorization
。
参数
Request URL: https://www.linkedin.com/v2/jobs
Request type: GET
Parameters
Authorization: Bearer <access_token>
Run Code Online (Sandbox Code Playgroud)
请求后,用户将看到 LinkedIn 的身份验证屏幕,并要求其批准该请求。
用户批准请求并<redirect_uri>
经过验证后,用户将被重定向到提供的<redirect_uri>
访问代码<access_code>
和参数中的值state
。假设在状态参数是<state_value>
。
出于安全目的,请在使用获取访问令牌之前验证 是否<state_value>
等于。另外,出于安全原因,请在发布后 30 分钟内使用。<random_string>
<access_code>
<access_code>
接下来,发送包含以下信息的 POST 请求https://www.linkedin.com/oauth/v2/accessToken
以获取访问令牌。
参数
response_type : code
client_id : <client_id>
redirect_uri : <redirect_uri>
state : <random_string>
scope : r_emailaddress%20w_member_social
Run Code Online (Sandbox Code Playgroud)
注意:authorization_code
是要传入的文字文本grant_type
。
您应该得到与客户端凭据工作流程类似的响应,其中包含您的访问令牌和到期时间。
回复
grant_type : authorization_code
client_id : <client_id>
client_secret : <client_secret>
redirect_uri : <redirect_uri>
code : <access_code>
Run Code Online (Sandbox Code Playgroud)
使用<access_token>
步骤 9 中获得的 API 请求。
例子
Request URL: `https://www.linkedin.com/v2/me`
Request type: GET
Parameters:
Authorization: Bearer <access_token>
Run Code Online (Sandbox Code Playgroud)
Postman 的设计就是为了让此类操作变得更容易,但你必须知道如何去做。有关更多详细信息,您可以阅读他们的官方文档。
归档时间: |
|
查看次数: |
9481 次 |
最近记录: |