linkedin:消息未发布

时间:2013-01-19 05:45:09

标签: java android linkedin

我正在做android集成以共享android中的数据,在提供用户名和密码并点击“登录并允许”按钮后,我无法移动到下一页而是回到上一页,还有没有张贴在墙上的数据,我尝试了很多教程,链接,但无法找到我的错误和挣扎很多,任何人都可以请帮助我。 这是我的MainActivity代码

public class MainActivity extends Activity {
public static final String CONSUMER_KEY             = "key";
public static final String CONSUMER_SECRET          = "secret";    
public static final String APP_NAME                 = "rebuix";
public static final String OAUTH_CALLBACK_SCHEME    = "x-oauthflow-linkedin";
public static final String OAUTH_CALLBACK_HOST      = "litestcalback";
public static final String OAUTH_CALLBACK_URL       = OAUTH_CALLBACK_SCHEME + "://"   +    OAUTH_CALLBACK_HOST;


LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory
        .getInstance().createLinkedInOAuthService(CONSUMER_KEY,
                CONSUMER_SECRET);
LinkedInApiClientFactory factory = LinkedInApiClientFactory
        .newInstance(CONSUMER_KEY, CONSUMER_SECRET);
LinkedInRequestToken liToken;
LinkedInApiClient client;


@SuppressLint({ "NewApi", "NewApi", "NewApi" })
Button btnLinkedin;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new   StrictMode.ThreadPolicy.Builder()
                .permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    Button btnLinkedinMain = (Button) findViewById(R.id.btnLinkedin);
    btnLinkedinMain.setOnClickListener(new View.OnClickListener() {



public void onClick(View v) {

    if (v.getId() == R.id.btnLinkedin) {

        oAuthService = LinkedInOAuthServiceFactory.getInstance()
                .createLinkedInOAuthService(Constants.CONSUMER_KEY,
                        Constants.CONSUMER_SECRET);
        System.out.println("oAuthService : " + oAuthService);

        factory = LinkedInApiClientFactory.newInstance(
                Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);

        liToken = oAuthService
                .getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL);

        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken
                .getAuthorizationUrl()));

        i.putExtra( "sms_body", false );
        try
        { 
                       startActivity(i);
    } catch (ActivityNotFoundException e) {
        // Display some sort of error message here.
    }
    }
}

protected void onNewIntent(Intent intent) {


    try {
        linkedInImport(intent);
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

private void linkedInImport(Intent intent) {
    String verifier = intent.getData().getQueryParameter("oauth_verifier");
    System.out.println("liToken " + liToken);
    System.out.println("verifier " + verifier);

    LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(
            liToken, verifier);
    client = factory.createLinkedInApiClient(accessToken);

    // client.postNetworkUpdate("LinkedIn Android app test");

    Person profile = client.getProfileForCurrentUser(EnumSet.of(
            ProfileField.ID, ProfileField.FIRST_NAME,
            ProfileField.LAST_NAME, ProfileField.HEADLINE));

    System.out.println("First Name :: " + profile.getFirstName());
    System.out.println("Last Name :: " + profile.getLastName());
    System.out.println("Head Line :: " + profile.getHeadline());

};

    });
}
    }

1 个答案:

答案 0 :(得分:0)

试用本教程...您将在本教程中获得消息发布功能..并在您的应用中逐步集成,请参阅此链接... http://code.google.com/p/socialauth-android/wiki/Linkedin

https://github.com/srivastavavivek1987/LinkedIn-Connection-in-Android