android linkedIn 集成 - 未收到访问令牌

android linkedIn integration- acces token not received

我正在尝试将我的应用程序与 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} 的授权令牌,分享部分显示“未设置访问令牌”

我使用了 here 的最新 LinkedId SDK。

此 SDK 已被弃用,3 月 1 日将删除 APIv1。

Please see

Also you can see the migration guide on his official docs

我创建了一个小库来通过 OAuth2 实现 LinkedIn 身份验证,因为 LinkedIn Mobile SDK 已被弃用

图书馆 - https://github.com/Sumudu-Sahan/LinkedInManager

步骤

  1. 将以下 maven 依赖项添加到您的项目级别 build.gradle 文件

    allprojects { repositories { ... maven { url 'https://jitpack.io' } } }

  2. 将以下 Maven 依赖项添加到您的应用级别 build.gradle 文件

    dependencies { implementation 'com.github.Sumudu-Sahan:LinkedInManager:1.00.02' }

  3. 继承您的 activity,来自 LinkedInManagerResponse

    的片段

    public class MainActivity extends AppCompatActivity implements LinkedInManagerResponse

  4. 启动登录过程的LinkedInRequestManager对象实例

    LinkedInRequestManager linkedInRequestManager = new LinkedInRequestManager(Activity, LinkedInManagerResponse, "CLIENT ID", "CLIENT SECRET", "REDIRECTION URL");

  5. 使用以下语句开始验证

linkedInRequestManager.showAuthenticateView(LinkedInRequestManager.MODE_BOTH_OPTIONS);

可用模式

LinkedInRequestManager.MODE_EMAIL_ADDRESS_ONLY
LinkedInRequestManager.MODE_LITE_PROFILE_ONLY
LinkedInRequestManager.MODE_BOTH_OPTIONS