如何使用社交认证库在linkedin和Twitter上分享

时间:2014-05-09 22:33:56

标签: android twitter linkedin socialauth

正在开发一个能够使用socialauth库在linkedin,facebook和twitter上共享内容的应用程序。它适用于Facebook,但它无法与twitter和linkedin共享。我收到一条警告,"提供商不支持" 下面是使用

的代码
socialauthadapter.authorize(this, Provider.TWITTER);
......
private final class ResponseListener implements DialogListener {
    public void onComplete(Bundle values) {

        try {
            socialauthadapter
                    .updateStory(
                            headtv.getText().toString().trim(),
                            "Africa Progress Panel",
                            "Download APP .",
                            "This year's report calls on African leaders to tackle inequality and demands global community tackle. Let your voice be heard. Download APP",
                            "http://africaprogresspanel.org",
                            Global.SERVER_MAIN_URI
                            + "uploads/pictures/reports/subtopics/"
                            + subtopic_photo,
                            new MessageListener());
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void onBack() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onCancel() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onError(SocialAuthError arg0) {
        // TODO Auto-generated method stub

    }
}

// To get status of message after authentication
public class MessageListener implements SocialAuthListener<Integer> {

    @Override
    public void onError(SocialAuthError arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onExecute(String arg0, Integer t) {

        Integer status = t;
        if (status.intValue() == 200 || status.intValue() == 201 ||status.intValue() == 204)
             Toast.makeText(ReportDetails.this, "Message posted",Toast.LENGTH_LONG).show();
    }

}

在logcat中,这就是我所看到的

Provider Not Supported

我该怎么做呢

NOTE:

- 所有密钥都正确

1 个答案:

答案 0 :(得分:1)

您可以尝试我的图书馆进行社交认证和分享:https://github.com/antonkrasov/AndroidSocialNetworks

它非常易于使用,只需使用您需要的社交网络构建Fragment:

mSocialNetworkManager = (SocialNetworkManager) getFragmentManager().findFragmentByTag(SOCIAL_NETWORK_TAG);

if (mSocialNetworkManager == null) {
    mSocialNetworkManager = SocialNetworkManager.Builder.from(getActivity())
            .twitter(<< TWITTER  API TOKEN  >>, << TWITTER  API SECRET  >>)
            .linkedIn(<< LINKED_IN API TOKEN  >>, << LINKED_IN API SECRET  >>, "r_basicprofile+rw_nus+r_network+w_messages")
            .facebook()
            .googlePlus()
            .build();
    getFragmentManager().beginTransaction().add(mSocialNetworkManager, SOCIAL_NETWORK_TAG).commit();
}

现在你可以分享:

mSocialNetworkManager.getTwitterSocialNetwork().requestPostMessage(message,
            new DemoOnPostingCompleteListener(message)
    );

private class DemoOnPostingCompleteListener implements OnPostingCompleteListener {
    private String mmMessage;

    private DemoOnPostingCompleteListener(String message) {
        mmMessage = message;
    }

    @Override
    public void onPostSuccessfully(int socialNetworkID) {
        hideProgress();

        handleSuccess("Success", "Message: '" + mmMessage + "' successfully posted.");
    }

    @Override
    public void onError(int socialNetworkID, String requestID, String errorMessage, Object data) {
        hideProgress();
        handleError(errorMessage);
    }
}

请查看Github回购获取更多信息,谢谢:)