我必须与android应用程序中的linkedIn集成。但是我没有访问代码。我尝试了很多方法,但没有用。这是我的代码。
LISessionManager.getInstance(getApplicationContext()).init(this, buildScope(), new AuthListener() {
@Override
public void onAuthSuccess() {
Log.e("LinkedIn", "User Loged in");
Toast.makeText(getApplicationContext(), "success" + LISessionManager.getInstance(getApplicationContext()).getSession().getAccessToken().toString(), Toast.LENGTH_LONG).show();
// LISessionManager.getInstance(getApplicationContext().getSession().getAccessToken().toString(), Toast.LENGTH_LONG).show();</p>
String authToken = LISessionManager.getInstance(getApplicationContext()).getSession().getAccessToken().toString();
Log.e("LinkedIn auth token", authToken);
shareLinkedInContent();
}
@Override
public void onAuthError(LIAuthError error) {
// Handle authentication errors
Log.e("LinkedIn", error.toString());
}
}, true);
private void shareLinkedInContent() {
String url = "https://api.linkedin.com/v1/people/~/shares";
Log.e("LinkedIn", "Posted" + url);
try {
JSONObject body = new JSONObject("{" +
"\"comment\": \"Sample share\"," +
"\"visibility\": { \"code\": \"anyone\" }," +
"\"content\": { " +
"\"title\": \"Sample share\"," +
"\"description\": \"Testing the mobile SDK call wrapper!\"," +
"\"submitted-url\": \"http://www.example.com/\"," +
"\"submitted-image-url\": \"http://www.example.com/pic.jpg\"" +
"}" +
"}");
Log.e("LinkedIn", "Posted" + url);
APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
apiHelper.postRequest(this, url, body, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse apiResponse) {
// Success!
Log.e("LinkedIn post success", "Posted");
}
@Override
public void onApiError(LIApiError liApiError) {
Log.e("LinkedIn post error", liApiError.getMessage());
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
我获得了像 {“ expiresOn”:0} 这样的身份验证令牌,并且共享部分提供了未设置访问令牌
我使用了https://stackoverflow.com/a/47710224/7477198中最新的LinkedId SDK。
我不知道如何解决这个问题。让我知道是否有人知道...
答案 0 :(得分:1)
答案 1 :(得分:0)
我创建了一个小型库以通过OAuth2实现LinkedIn身份验证,因为不推荐使用LinkedIn Mobile SDK
图书馆-https://github.com/Sumudu-Sahan/LinkedInManager
步骤
将以下Maven依赖项添加到您的项目级别build.gradle
文件中
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
将以下Maven依赖项添加到您的应用级build.gradle
文件中
dependencies {
implementation 'com.github.Sumudu-Sahan:LinkedInManager:1.00.02'
}
继承您的活动,来自LinkedInManagerResponse
public class MainActivity extends AppCompatActivity implements LinkedInManagerResponse
启动LinkedInRequestManager
对象实例以进行登录过程
LinkedInRequestManager linkedInRequestManager = new LinkedInRequestManager(Activity, LinkedInManagerResponse, "CLIENT ID", "CLIENT SECRET", "REDIRECTION URL");
使用以下语句开始验证
linkedInRequestManager.showAuthenticateView(LinkedInRequestManager.MODE_BOTH_OPTIONS);
可用模式
LinkedInRequestManager.MODE_EMAIL_ADDRESS_ONLY
LinkedInRequestManager.MODE_LITE_PROFILE_ONLY
LinkedInRequestManager.MODE_BOTH_OPTIONS