将图像附加到 Facebook 事件(php sdk、rest 或 graph api) [英] Attach image to Facebook event (php sdk, rest or graph api)

查看:22
本文介绍了将图像附加到 Facebook 事件(php sdk、rest 或 graph api)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
使用Graph API在facebook活动中添加图片

几个小时以来,我一直在尝试通过 Facebook API 创建一个带有图像的事件.到目前为止,我已经能够在没有图像的情况下通过 Graph 和 Rest API 创建事件,但无法附加任何图像.

I have been trying for a good few hours now to create an event through the Facebook API with an image. So far I have been able to create events though both the Graph and Rest APIs without images, but have been unable to attach any images.

我相信 REST API 是唯一支持附加图像的 API,但文档很差,而且 php-sdk 文档或代码也没有太大帮助.

I believe the REST API is the only API which supports attaching images, but the documentation is pretty poor and the php-sdk docs or code do not help much either.

我最近的尝试已结束:http://promos.uk.glam.com/splash_test/example.php

使用代码:http://pastebin.com/8JC8​​RAck(注意需要 facebook.php" 是 php-sdk - http://github.com/facebook/php-sdk/)

With the code: http://pastebin.com/8JC8RAck (note the "require facebook.php" is the php-sdk - http://github.com/facebook/php-sdk/)

注意第 93 行( "if ($uid) {" ),这应该是 "if ($me) {",它工作了一个小时左右,然后停止工作(没有更改代码填充 $me),奇怪.

Note line 93 ( "if ($uid) {" ), this is supposed to be "if ($me) {", which was working for an hour or so, and then stopped working (no changes to the code that populates $me), odd.

因此,事件创建代码是第 96-99 行,现在它创建了一个没有图像的事件,但是一旦我放回注释掉的代码(第 98 行),它就无法执行任何操作.

So, the event creation code is lines 96-99 and as it is now it creates an event without an image, but as soon as I put back in the commented out code (line 98, ) it fails to do anything.

有谁知道如何通过带有图像的 API 在 facebook 上创建事件?如果是这样,请在这里帮助我!尽管我必须使用 PHP 或 Javascript,但如果有其他解决方案,我在废弃所有这些代码时没有问题.

Does anyone know how to create events on facebook though the API with images? If so, please help me out here! I have no problems scrapping all this code if there is another solution, although I have to use PHP or Javascript.

谢谢大家

推荐答案

感谢大家的回答,我决定重新审视这个问题,看看 API 现在是否正常工作.这是!现在可以使用 Graph API 上传图片.感谢 Stan James 让我注意到这一点,并提供了发布照片的代码,我将这些代码用于活动:

Thanks everyone for your answers, I decided to revisit this to see if the API is working correctly now. It is! Uploading pictures with the Graph API now works. Thanks to Stan James for bringing my attention to this and giving code to post photos, which I adapted for events:

设置:

//Setup the Facebook object allowing file upload
$facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxx',
  'cookie' => true,
  'fileUpload' => true
));

发布:

//Path to photo (only tested with relative path to same directory)
$file = "end300.jpg";
//The event information array (timestamps are "Facebook time"...)
$event_info = array(
    "privacy_type" => "SECRET",
    "name" => "Event Title",
    "host" => "Me",
    "start_time" => 1290790800,
    "end_time" => 1290799800,
    "location" => "London",
    "description" => "Event Description"
);
//The key part - The path to the file with the CURL syntax
$event_info[basename($file)] = '@' . realpath($file);
//Make the call and get back the event ID
$result = $facebook->api('me/events','post',$event_info);

我已经把所有的代码都放在了 pastebin (http://pastebin.com/iV0JL2mL) 上,几个月前我的调试和对 Facebook 的愤怒让我觉得有点乱!但它有效.

I have put all the code on pastebin (http://pastebin.com/iV0JL2mL), it's a bit messy from my debugging and getting angry with Facebook months ago! But it works.

这篇关于将图像附加到 Facebook 事件(php sdk、rest 或 graph api)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆