将 LinkedIn 迁移到 API v2
Migrate LinkedIn to API v2
我正在使用 LinkedIn API v1
,看到公告:
All developers need to migrate their apps to our newest APIs and OAuth
2.0 by March 1, 2019.
我实现了新的 Oauth2 流程(它基本上是一样的,只是将端点和权限 r_basicprofile
更改为 r_liteprofile
)并且它有效并且 return 编辑了我的代码用于检索访问令牌。
获得访问令牌后,我调用了一个 return 用户的 firstName
、lastName
和 id
,另一个调用 [=21] =](之前只有 1 个请求,但没关系)。
这里我看到使用 Authorization
header 它 return 报了一个错误,说我没有通知访问令牌,但是如果我把访问令牌放在paramenter oauth2_access_token
我可以成功发出请求。
在他们的文档 (https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin?context=linkedin/consumer/context) they don't say where to put the access token, and in the Oauth2 flow docs (https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/consumer/context) 中,它使用 Authorization
header 和 v1 API。但是,无论如何,它使用 URL.
中的参数起作用
在 v1 中我正在做:
经过Oauth2授权后:
URL: https://api.linkedin.com/v1/people/~?oauth2_access_token={{accessToken}}&format=json
使用JavascriptSDK授权后:
URL: https://api.linkedin.com/v1/people/~
Header: oauth_token={{accessToken}}
使用Mobile SDK (Android)授权后:
URL: https://api.linkedin.com/v1/people/~
Header: Authorization=Bearer {{accessToken}}
Header: x-li-src=msdk
Header: x-li-format=json
有点混乱,因为每个都以不同的方式完成,但我无法使 v1
API 以通用方式处理上述 3 种情况.尽管如此,它还是奏效了。
但是现在,如何使用 v2 API 获取用户数据 ?
目前我只通过 Oauth2 Flow 实现了它:
URL: https://api.linkedin.com/v2/me?projection=(...)&oauth2_access_token={{accessToken}}
(从我看到其他人的帖子来看,他们使用 Authorization
Header 而不是 oauth2_access_token
参数,而我想使用 header,但只能让它与参数一起工作。如果有人知道如何让它与 header 一起工作,我将不胜感激。
无论如何,我的主要问题是:
如何从 v1
迁移到 v2
并使其以与现在 v1
相同的方式工作? (使用从前端和移动应用程序接收到的令牌,并从 back-end 中的该令牌检索用户信息,就像我在上面使用 v1
API 发布的 3 个案例一样,其中我只能使用 Oauth2 流程实现第一个。
不幸的是,移动和 javascript SDK 似乎已被弃用。看这里:https://engineering.linkedin.com/blog/2018/12/developer-program-updates
SDKs: Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps.
据我所知,由于 OAuth 流程仅在浏览器中可用,您现在需要转到 Web 才能在移动设备上进行身份验证。
我正在使用 LinkedIn API v1
,看到公告:
All developers need to migrate their apps to our newest APIs and OAuth 2.0 by March 1, 2019.
我实现了新的 Oauth2 流程(它基本上是一样的,只是将端点和权限 r_basicprofile
更改为 r_liteprofile
)并且它有效并且 return 编辑了我的代码用于检索访问令牌。
获得访问令牌后,我调用了一个 return 用户的 firstName
、lastName
和 id
,另一个调用 [=21] =](之前只有 1 个请求,但没关系)。
这里我看到使用 Authorization
header 它 return 报了一个错误,说我没有通知访问令牌,但是如果我把访问令牌放在paramenter oauth2_access_token
我可以成功发出请求。
在他们的文档 (https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin?context=linkedin/consumer/context) they don't say where to put the access token, and in the Oauth2 flow docs (https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/consumer/context) 中,它使用 Authorization
header 和 v1 API。但是,无论如何,它使用 URL.
在 v1 中我正在做:
经过Oauth2授权后:
URL: https://api.linkedin.com/v1/people/~?oauth2_access_token={{accessToken}}&format=json
使用JavascriptSDK授权后:
URL: https://api.linkedin.com/v1/people/~
Header: oauth_token={{accessToken}}
使用Mobile SDK (Android)授权后:
URL: https://api.linkedin.com/v1/people/~
Header: Authorization=Bearer {{accessToken}}
Header: x-li-src=msdk
Header: x-li-format=json
有点混乱,因为每个都以不同的方式完成,但我无法使 v1
API 以通用方式处理上述 3 种情况.尽管如此,它还是奏效了。
但是现在,如何使用 v2 API 获取用户数据 ?
目前我只通过 Oauth2 Flow 实现了它:
URL: https://api.linkedin.com/v2/me?projection=(...)&oauth2_access_token={{accessToken}}
(从我看到其他人的帖子来看,他们使用 Authorization
Header 而不是 oauth2_access_token
参数,而我想使用 header,但只能让它与参数一起工作。如果有人知道如何让它与 header 一起工作,我将不胜感激。
无论如何,我的主要问题是:
如何从 v1
迁移到 v2
并使其以与现在 v1
相同的方式工作? (使用从前端和移动应用程序接收到的令牌,并从 back-end 中的该令牌检索用户信息,就像我在上面使用 v1
API 发布的 3 个案例一样,其中我只能使用 Oauth2 流程实现第一个。
不幸的是,移动和 javascript SDK 似乎已被弃用。看这里:https://engineering.linkedin.com/blog/2018/12/developer-program-updates
SDKs: Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps.
据我所知,由于 OAuth 流程仅在浏览器中可用,您现在需要转到 Web 才能在移动设备上进行身份验证。