0

我正在进行linkedin集成以在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());

};

    });
}
    }
4

1 回答 1

0

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

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

于 2013-01-19T05:54:58.270 回答