通过 Spring Social 使用图像创建 Facebook 事件

发布于 2024-12-10 15:22:52 字数 290 浏览 2 评论 0原文

查看 spring 社交 facebook api,EventOperations 提供

    createEvent(java.lang.String name, java.lang.String startTime, 
                                                      java.lang.String endTime)

将事件发布到 facebook 的功能。

有没有办法发布活动的更多信息,例如活动图片和活动描述?

Looking over the spring social facebook api, EventOperations offers

    createEvent(java.lang.String name, java.lang.String startTime, 
                                                      java.lang.String endTime)

to post Events to facebook.

Is there a way to post more information for the event, like event image and event description?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夢归不見 2024-12-17 15:22:52

查看createEvent方法,它当前不支持附件(事件图像)。然而,它确实调用 GraphApi publish 来实际发布事件:

public String createEvent(String name, String startTime, String endTime) {
    requireAuthorization();
    MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();
    data.set("name", name);
    data.set("start_time", startTime);
    data.set("end_time", endTime);
    return graphApi.publish("me", "events", data);
}

graphApi.publish(...) 本身(在 Facebook 模板 )将支持任何东西作为 Facebook 准备接受的 {key,value} 对,因为它只是委托给 RestTemplate,并通过常规 HTTP POST 将所有 {key,value} 对提供给 Facebook :

public String publish(String objectId, String connectionType, MultiValueMap<String, Object> data) {
    MultiValueMap<String, Object> requestData = new LinkedMultiValueMap<String, Object>(data);
    URI uri = URIBuilder.fromUri(GRAPH_API_URL + objectId + "/" + connectionType).build();
    Map<String, Object> response = getRestTemplate().postForObject(uri, requestData, Map.class);
    return (String) response.get("id");
}

因此您可以扩展 EventTemplate 并添加另一个 createEvent 方法,该方法将采用图像名称图像文件路径,并将其作为附加的 {key,value} 添加到 data MultiMap 中:

data.set( "@" + imageName, "@" + imagePath )

因此该方法看起来接近于:

public String createEvent( String name, 
                           String startTime, 
                           String endTime,
                           String imageName,
                           String imagePath ) {   // or maybe even "File image", where you would derive the path
    requireAuthorization();
    MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();
    data.set("name", name);
    data.set("start_time", startTime);
    data.set("end_time", endTime);

    data.set( "@" + imageName, "@" + imagePath );  // <<< adding this line

    return graphApi.publish("me", "events", data);
}

这当然不包括您可能想要执行的任何可能的验证等。 。
一旦你完成了这项工作(这似乎非常简单),你可以将其捐赠/贡献回 Spring Social =>他们会很高兴:)

Looking at createEvent method, it does not currently support the attachment (event image). It does however call into GraphApi publish to actually publish the event:

public String createEvent(String name, String startTime, String endTime) {
    requireAuthorization();
    MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();
    data.set("name", name);
    data.set("start_time", startTime);
    data.set("end_time", endTime);
    return graphApi.publish("me", "events", data);
}

graphApi.publish(...) itself ( which is implemented in FacebookTemplate ) would support anything as a {key,value} pair that Facebook is ready to accept, as it just delegates to the RestTemplate, and feeds all the {key,value} pairs to Facebook through a regular HTTP POST:

public String publish(String objectId, String connectionType, MultiValueMap<String, Object> data) {
    MultiValueMap<String, Object> requestData = new LinkedMultiValueMap<String, Object>(data);
    URI uri = URIBuilder.fromUri(GRAPH_API_URL + objectId + "/" + connectionType).build();
    Map<String, Object> response = getRestTemplate().postForObject(uri, requestData, Map.class);
    return (String) response.get("id");
}

Hence you can extend the EventTemplate and add another createEvent method, that would take an image name and an image file path, and would added it as an additional {key,value} to a data MultiMap:

data.set( "@" + imageName, "@" + imagePath )

Hence the method would look close to:

public String createEvent( String name, 
                           String startTime, 
                           String endTime,
                           String imageName,
                           String imagePath ) {   // or maybe even "File image", where you would derive the path
    requireAuthorization();
    MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();
    data.set("name", name);
    data.set("start_time", startTime);
    data.set("end_time", endTime);

    data.set( "@" + imageName, "@" + imagePath );  // <<< adding this line

    return graphApi.publish("me", "events", data);
}

This of course does not include any possible validation that you might want to do, etc..
Once you have this working, which seems to be pretty straightforward, you can donate / contribute it back to Spring Social => they'd be very pleased :)

旧城烟雨 2024-12-17 15:22:52

尽管当时提供的答案可能是正确的,但现在这个答案具有误导性和错误性。从 v2.1 开始,您无法通过 API 创建/更新/删除事件。

https://developers.facebook.com/docs/graph- api/reference/v2.1/event/

Although answer provided was possibly correct at the time, nowadays this answer is misleading and wrong. Since v2.1 onwards you can't do CREATE/UPDATE/DELETE of Events via API.

https://developers.facebook.com/docs/graph-api/reference/v2.1/event/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文