与linkedin OAuth 2分享

时间:2016-03-21 13:10:35

标签: android oauth-2.0 linkedin retrofit2

我正在尝试与linkedin分享帖子并使用OAuth 2登录,但我收到了此回复

`{
  "errorCode": 0,
  "message": "Access to shares denied",
  "requestId": "0N4OYBHUMX",
  "status": 403,
  "timestamp": 1458564792498
}`

使用Retrofit 2建立连接,我发布了此标头,如documentation所述。

@POST("people/~/shares")
Call<SilentShareLinkedInModel> SilentShareLinkedIn(@Query("oauth2_access_token") String accessToken,
                                                   @Query("format") String format,
                                                   @Header("Content-Type") String ContentType,
                                                   @Header("x-li-format") String xliformat);

这是方法调用:

private void shareLinked() {
    String aboutTrip = searchWriteSomething.getText().toString();
    SharedPreferences prefs = getActivity().getSharedPreferences("user_info", 0);
    String token = prefs.getString("accessToken", "");
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://api.linkedin.com/v1/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    LinkedAPI api = retrofit.create(LinkedAPI.class);
    SilentShareLinkedInModel model =
            new SilentShareLinkedInModel(aboutTrip, new VisibilityModel("anyone"));
    Call<SilentShareLinkedInModel> response = api.SilentShareLinkedIn(token, "json","application/json","json");
    response.enqueue(new Callback<SilentShareLinkedInModel>() {
        @Override
        public void onResponse(Call<SilentShareLinkedInModel> call, Response<SilentShareLinkedInModel> response) {
            Toast.makeText(getActivity(), "Posted to linked", Toast.LENGTH_LONG).show();
            Log.wtf("ShareLinked", response.raw().toString());
        }

        @Override
        public void onFailure(Call<SilentShareLinkedInModel> call, Throwable t) {
            Toast.makeText(getActivity(), "failed Post to linked", Toast.LENGTH_LONG).show();

        }
    });
}

我也在登录过程中使用了这些权限范围

r_basicprofile%20r_emailaddress%20r_network%20w_share

此代码中的错误以及为何总是显示此消息?

  

拒绝访问股票

0 个答案:

没有答案