2

使用下面的代码,我可以使用 LinkedIn 共享文本。是否可以通过提供图像路径来共享图像 url,例如:“/SDCARD/abc.png”,就像在 TWITTER 中一样

    private LinkedInOAuthService oAuthService;
private LinkedInApiClientFactory factory;
private LinkedInRequestToken liToken;
private LinkedInApiClient client;
public static final String LINKEDIN_PREF = "GamePrefs";

@SuppressLint({ "NewApi", "NewApi", "NewApi" })
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.linkedin);

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

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

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

    liToken = oAuthService.getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL);
    System.out.println("onCreate:linktoURL : " + liToken.getAuthorizationUrl());
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl()));
    startActivity(i);

}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(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);
    //SharedPreferences settings = getSharedPreferences(LINKEDIN_PREF, MODE_PRIVATE);
    // final Editor edit = settings.edit();
    // edit.putString(OAuth.OAUTH_TOKEN, accessToken.getToken());
    // edit.putString(OAuth.OAUTH_TOKEN_SECRET,
    // accessToken.getTokenSecret());
    // edit.putString("linkedin_login", "valid");
    // edit.commit();

    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());

    OAuthConsumer consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
    consumer.setTokenWithSecret(accessToken.getToken(), accessToken.getTokenSecret());

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost post = new HttpPost("https://api.linkedin.com/v1/people/~/shares");
    try {
        consumer.sign(post);
        post.setHeader("content-type", "text/XML");
        String myEntity = "<share><comment>This is a test</comment><<submitted-image-url> </submitted-image-url><visibility><code>anyone</code></visibility></share>";
        post.setEntity(new StringEntity(myEntity));
        org.apache.http.HttpResponse response = httpclient.execute(post);
        // Get the response
        BufferedReader rd = new BufferedReader
          (new InputStreamReader(response.getEntity().getContent()));
        StringBuffer strBfr = new StringBuffer();   
        String line = "";
        while ((line = rd.readLine()) != null) {

            strBfr.append(line);
        } 
        System.out.println("Response is : "+strBfr.toString());
        Toast.makeText(ShareInLinkedIn.this, strBfr.toString(), Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}

}

LinkedIn API 网站上,它说您可以通过以下方式提交:

   submitted-url    URL for shared content  
   submitted-image-url  URL for image of shared content

但找不到基于submit-image-url 的示例。任何机构都可以帮我找出如何做到这一点吗?

4

0 回答 0