【问题标题】:facebook: Post photo to timeline with restfbfacebook:使用 restfb 将照片发布到时间线
【发布时间】:2014-04-02 12:55:11
【问题描述】:

我正在尝试使用 restfb 将照片发布到用户的页面时间轴。

我的代码是这样的:

// Create parameters for the call
Collection<Parameter> params = new ArrayList<Parameter>();
params.add(Parameter.with("message", "My Message"));
Parameter postParamsArray[] = params.toArray(new Parameter[params.size()]);
java.net.URL url = new java.net.URL("http://i.istockimg.com/file_thumbview_approve/4739627/2/stock-illustration-4739627-dreidel-game.jpg");
FacebookType publishMessageResponse = facebookClient.publish(facebookWallURL, FacebookType.class,BinaryAttachment.with("dreidel.jpg", url.openStream()), postParamsArray);

但是,我在时间线上只看到文本:我的消息。

用户拥有以下权限:

'manage_pages, publish_stream, create_event, photo_upload'

可能是什么问题?

【问题讨论】:

    标签: java facebook facebook-graph-api restfb


    【解决方案1】:

    facebookWallURL - 看起来您要在墙上发帖。尝试发布到相册:

    facebookURL = facebookPageId + "/photos";
    publishMessageResponse = facebookClient.publish(facebookURL, FacebookType.class, ba, postParamsArray);
    

    如本例中所写:
    (注意“我/视频”
    http://restfb.com/

    Publishing a Photo (see Graph API documentation)
    
    // Publishing an image to a photo album is easy
    // Just specify the image you'd like to upload and RestFB will handle it from there.
    
    FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,
      BinaryAttachment.with("cat.png", getClass().getResourceAsStream("/cat.png")),
      Parameter.with("message", "Test cat"));
    
    out.println("Published photo ID: " + publishPhotoResponse.getId());
    
    // Publishing a video works the same way as uploading a photo.
    
    facebookClient.publish("me/videos", FacebookType.class,
      BinaryAttachment.with("cat.mov", getClass().getResourceAsStream("/cat.mov")),
      Parameter.with("message", "Test cat"));
    

    【讨论】:

    • @urlr 它对我不起作用.....在线程“main”java.lang.IllegalArgumentException 中显示异常异常:二进制附件数据不能为空。
    • @sooraj 这只是意味着您的流实际上是空的。这段代码 getClass().getResourceAsStream("/cat.png") 到一个单独的属性,看看它可能是空的。解决您的文件加载问题,代码将完美运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 2012-01-15
    相关资源
    最近更新 更多