Android LinkedIn SDK 生成无法使用的访问令牌
Android LinkedIn SDK produces unusable access tokens
我想要完成的事情:
- 通过 LinkedIn 的 Android SDK
进行身份验证
- 获取用户的个人资料以获得他们的 userId
- 针对我们的内部服务创建新用户
到目前为止,我已经能够通过 LinkedIn 进行身份验证,检索访问令牌,并将其用于 LinkedIn 的服务以获取他们的用户 ID。
流程看起来有点像这样
LISessionManager.getInstance(activity).init(this.activity.get(), permissionScope,
authLinkedInCallback, showDialogIfAppMissing);
返回到我的应用程序后,我使用以下代码捕获了 Intent 数据
LISessionManager.getInstance(activity).onActivityResult(activity, requestCode, resultCode, data);
这部分似乎可以正常工作,并从 LISessionManager[=60] 中的 AuthListener 设置中产生一个 onAuthSuccess =] 初始化.
post 成功我可以使用提供的访问令牌和提供的 APIHelper 来获取用户的基本配置文件
String built = "https://api.linkedin.com/v1/people/~?format=json";
APIHelper.getInstance(activity.get()).getRequest(activity.get(), built, getProfileCallback);
这实际上 returns 成功地获得了基本的用户配置文件信息。
这就是问题所在 我只能使用此访问令牌通过 APIHelper 进行调用。当尝试在其他地方(服务器端,在 Postman/Apigee 中测试)使用提供的访问令牌时,它总是 returns 这个响应。
{
"errorCode": 0,
"message": "Unable to verify access token",
"requestId": "M9J2NBQV9J",
"status": 401,
"timestamp": 1430922872474
}
我一直在使用 LinkedIn 资源调试 401 问题 (https://developer.linkedin.com/docs/oauth2) 使用 LISessionManager。评估当前会话告诉我访问令牌是
- 仍然有效
- 尚未过期
- 自发行之日起大约 2 个月内仍然有效。
查看我的LinkedIn个人资料,它没有撤销对应用程序的访问权限,权限范围是basic_profile、email_address和w_share
我真的很困惑为什么这些生成的 accessTokens 在 LinkedIn SDK 之外似乎无效,它们在整个服务中都无效吗?
感谢任何帮助。
如 LinkedIn 的 Android SDK 身份验证文档 (https://developer.linkedin.com/docs/android-sdk-auth) 所述,
Mobile vs. server-side access tokens
It is important to note that access tokens that are acquired via the Mobile SDK are only useable with the Mobile SDK, and cannot be used to make server-side REST API calls.
Similarly, access tokens that you already have stored from your users that authenticated using a server-side REST API call will not work with the Mobile SDK.
LISessionManager sessionManager = LISessionManager.getInstance(getApplicationContext());
LISession session = sessionManager.getSession();
boolean accessTokenValid = session.isValid();
String respon ="";
if(accessTokenValid) {
String url = "https://api.linkedin.com/v1/people/~?format=json";
//String url = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url)";
APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
apiHelper.getRequest("your activity", url, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse apiResponse) {
respon = apiResponse.toString();
Log.e("Response ", respon);
}
@Override
public void onApiError(LIApiError LIApiError) {
Log.e("error", LIApiError.toString());
}
});
}
虽然 LinkedIn 声明无法使用 Mobile SDK 提供的访问令牌进行 server-side API 调用,但我可以通过添加 x-li-src: msdk
在请求的 header 中。
我想要完成的事情:
- 通过 LinkedIn 的 Android SDK 进行身份验证
- 获取用户的个人资料以获得他们的 userId
- 针对我们的内部服务创建新用户
到目前为止,我已经能够通过 LinkedIn 进行身份验证,检索访问令牌,并将其用于 LinkedIn 的服务以获取他们的用户 ID。
流程看起来有点像这样
LISessionManager.getInstance(activity).init(this.activity.get(), permissionScope,
authLinkedInCallback, showDialogIfAppMissing);
返回到我的应用程序后,我使用以下代码捕获了 Intent 数据
LISessionManager.getInstance(activity).onActivityResult(activity, requestCode, resultCode, data);
这部分似乎可以正常工作,并从 LISessionManager[=60] 中的 AuthListener 设置中产生一个 onAuthSuccess =] 初始化.
post 成功我可以使用提供的访问令牌和提供的 APIHelper 来获取用户的基本配置文件
String built = "https://api.linkedin.com/v1/people/~?format=json";
APIHelper.getInstance(activity.get()).getRequest(activity.get(), built, getProfileCallback);
这实际上 returns 成功地获得了基本的用户配置文件信息。
这就是问题所在 我只能使用此访问令牌通过 APIHelper 进行调用。当尝试在其他地方(服务器端,在 Postman/Apigee 中测试)使用提供的访问令牌时,它总是 returns 这个响应。
{
"errorCode": 0,
"message": "Unable to verify access token",
"requestId": "M9J2NBQV9J",
"status": 401,
"timestamp": 1430922872474
}
我一直在使用 LinkedIn 资源调试 401 问题 (https://developer.linkedin.com/docs/oauth2) 使用 LISessionManager。评估当前会话告诉我访问令牌是
- 仍然有效
- 尚未过期
- 自发行之日起大约 2 个月内仍然有效。
查看我的LinkedIn个人资料,它没有撤销对应用程序的访问权限,权限范围是basic_profile、email_address和w_share
我真的很困惑为什么这些生成的 accessTokens 在 LinkedIn SDK 之外似乎无效,它们在整个服务中都无效吗?
感谢任何帮助。
如 LinkedIn 的 Android SDK 身份验证文档 (https://developer.linkedin.com/docs/android-sdk-auth) 所述,
Mobile vs. server-side access tokens
It is important to note that access tokens that are acquired via the Mobile SDK are only useable with the Mobile SDK, and cannot be used to make server-side REST API calls.
Similarly, access tokens that you already have stored from your users that authenticated using a server-side REST API call will not work with the Mobile SDK.
LISessionManager sessionManager = LISessionManager.getInstance(getApplicationContext());
LISession session = sessionManager.getSession();
boolean accessTokenValid = session.isValid();
String respon ="";
if(accessTokenValid) {
String url = "https://api.linkedin.com/v1/people/~?format=json";
//String url = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url)";
APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
apiHelper.getRequest("your activity", url, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse apiResponse) {
respon = apiResponse.toString();
Log.e("Response ", respon);
}
@Override
public void onApiError(LIApiError LIApiError) {
Log.e("error", LIApiError.toString());
}
});
}
虽然 LinkedIn 声明无法使用 Mobile SDK 提供的访问令牌进行 server-side API 调用,但我可以通过添加 x-li-src: msdk
在请求的 header 中。