在LinkedIn上共享时获取HTTP 400

时间:2015-06-05 14:41:02

标签: java share linkedin linkedin-j linkedin-api

我想代表那些已经过我的应用程序验证的用户分享给LinkedIn。但是获取HTTP 400状态代码。

这是我的代码

    Document doc = DocumentHelper.createDocument();
    Element share = doc.addElement("share");
    share.addElement("comment").addText("Guess who is testing the LinkedIn REST APIs");
    Element content = share.addElement("content");
    content.addElement("title").addText("A title for your share");
    content.addElement("submitted-url").addText("http://developer.linkedin.com");
    share.addElement("visibility").addElement("code").addText("anyone");
    String access_token = "XXXXXXXXXXXXXXXXXXXXXX";

    List <NameValuePair> nvps = new ArrayList <NameValuePair>();
    nvps.add(new BasicNameValuePair("text/xml", doc.asXML()));

    URI uri = new URIBuilder().setScheme("https")
            .setHost("api.linkedin.com")
            .setPath("/v1/people/~/shares")
            .build();

    DefaultHttpClient client2 = new DefaultHttpClient();
    HttpPost post = new HttpPost(uri);        
    post.setHeader("Authorization", "Bearer "+access_token);        
    post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));        
    HttpResponse profileResponse = client2.execute(post);

请帮忙。任何帮助将不胜感激。

0 个答案:

没有答案