[英]Android LinkedIn SDK produces unusable access tokens
我想要完成的事情:
到目前為止,我已經能夠通過LinkedIn進行身份驗證,檢索訪問令牌,並使用針對LinkedIn的服務獲取其用戶ID。
流程看起來有點像這樣
LISessionManager.getInstance(activity).init(this.activity.get(), permissionScope,
authLinkedInCallback, showDialogIfAppMissing);
返回我的應用程序后,我使用下面的代碼捕獲Intent數據
LISessionManager.getInstance(activity).onActivityResult(activity, requestCode, resultCode, data);
這部分似乎是功能性,並產生從AuthListener設置在LISessionManager初始化一個onAuthSuccess。
發布成功我可以使用提供的訪問令牌和提供的APIHelper來獲取用戶的基本配置文件
String built = "https://api.linkedin.com/v1/people/~?format=json";
APIHelper.getInstance(activity.get()).getRequest(activity.get(), built, getProfileCallback);
這實際上與基本用戶配置文件信息成功返回。
這就是問題所在,我只能使用這個訪問令牌來使用APIHelper進行調用。 當嘗試在其他地方使用提供的訪問令牌(服務器端,在Postman / Apigee中進行測試)時,它總是返回此響應。
{
"errorCode": 0,
"message": "Unable to verify access token",
"requestId": "M9J2NBQV9J",
"status": 401,
"timestamp": 1430922872474
}
我一直在使用LinkedIn資源調試401問題( https://developer.linkedin.com/docs/oauth2 )使用LISessionManager 。 評估當前會話告訴我訪問令牌是
檢查我的LinkedIn個人資料,它沒有撤銷對應用程序的訪問權限,權限范圍是basic_profile,email_address和w_share
我真的很困惑為什么這些生成的accessTokens在LinkedIn SDK之外似乎沒有效果,它們在整個服務中無效嗎?
任何幫助贊賞。
如LinkedIn的Android SDK身份驗證文檔( https://developer.linkedin.com/docs/android-sdk-auth )所述,
移動與服務器端訪問令牌
請務必注意,通過Mobile SDK獲取的訪問令牌僅可用於Mobile SDK,並且不能用於進行服務器端REST API調用。
同樣,您已經從使用服務器端REST API調用進行身份驗證的用戶存儲的訪問令牌將無法與Mobile SDK一起使用。
雖然LinkedIn聲明無法使用Mobile SDK提供的訪問令牌來進行服務器端API調用,但我只能通過在請求的標頭中添加x-li-src: msdk
來進行此類調用。
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());
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.