English 中文(简体)
使用书签库将图像张贴到脸书页面
原标题:Using scribe library to post image to Facebook Page

I am trying to post an image to facebook using scribe library. My code is:

String apiKey = "MY_API_KEY";
        String apiSecret = "MY_SECRET_KEY";
        OAuthService service = new ServiceBuilder().provider(FacebookApi.class).apiKey(apiKey)
                .apiSecret(apiSecret)
                .callback("MY_CALL_BACK_URL")
                .build();

        Token accessToken = new Token("MY_ACCESS_TOKEN","");
        OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL_STREAM);       
        request.addHeader("Content-Type", "text/html");      
        request.addBodyParameter("message", "Testing auto update.. Please ignore " + new DateTime());           
        //MultiPart for pic
        Multipart mp = new MimeMultipart();
        MimeBodyPart htmlPart = new MimeBodyPart();
        ByteArrayOutputStream out = new ByteArrayOutputStream();    
        try {
            byte[] imagePayLoad = msgBody.getBytes("UTF-8");    //msgBody contains html string   
            byte[] mpByte = new byte[imagePayLoad.length];
            htmlPart.setContent(msgBody, "text/html");
            mp.addBodyPart(htmlPart);           
            //here I get the bytes[] of mp to out
            mp.writeTo(out);
            out.write(mpByte);      

            request.addPayload(mpByte);
        } catch (Exception e) {         
            e.printStackTrace();
        }   
        service.signRequest(accessToken, request);
        Response response = request.send();
        System.out.println("Response");
        System.out.println();    
        System.out.println(response.getCode());
        System.out.println(response.getBody());

    }

但我也得到

400
{"error":{"message":"(#100) Missing message or attachment","type":"OAuthException","code":100}}

任何人都能帮忙吗? 如果我拿出多部分, “测试自动更新。 请更新 i ” 的文本将更新到 Facebook 。 我需要上传图片和字节 。

谢谢 谢谢

我用的是:

 <dependency>
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<version>1.3.0</version>
</dependency>
问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签