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

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

问题描述


可能重复:

使用Graph API在Facebook事件中添加图片


我一直在尝试几个小时,通过Facebook API通过图像创建一个活动。到目前为止,我已经能够通过无图像的Graph和Rest API创建事件,但无法附加任何图像。



我相信REST API是仅支持附加图像的API,但文档相当差,php-sdk文档或代码也没有帮助。



我的最新尝试结束于: a href =http://promos.uk.glam.com/splash_test/example.php =nofollow noreferrer> http://promos.uk.glam.com/splash_test/example.php



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



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



所以,事件创建代码是96-99行,现在它创建一个没有图像的事件,但是一旦我放回注释掉的代码(行有没有人知道如何通过API与图像在Facebook上创建事件?如果是这样,请帮我在这里!如果有其他解决方案,我没有任何问题,尽管我必须使用PHP或Javascript。



感谢所有

解决方案

感谢大家的答案,我决定重新审视这一点,看看API现在是否正常工作。它是!使用Graph API上传图片现在可以正常工作。感谢斯坦·詹姆斯带给我的注意力,并提供了照片的照片,我修改了事件:



设置:

  //设置允许文件上传的Facebook对象
$ facebook = new Facebook(array(
'appId'=>'xxxxxxxxxxxxxxxxxxxx',
'secret'=>'xxxxxxxxxxxxxxxxxxxx',
'cookie'=> true,
'fileUpload'=> true
));

发布:

 code> //照片路径(仅通过相同目录的相对路径进行测试)
$ file =end300.jpg;
//事件信息数组(时间戳为Facebook时间...)
$ event_info = array(
privacy_type=>SECRET,
name =>事件标题,
host=>我,
start_time=> 1290790800,
end_time=> 1290799800,
location=>London,
description=>Event Description
);
//关键部分 - 使用CURL语法的文件路径
$ event_info [basename($ file)] ='@'。真实路径($文件);
//发出呼叫并返回事件ID
$ result = $ facebook-> api('me / events','post',$ event_info);

我把所有的代码放在了pastebin(http://pastebin.com/iV0JL2mL)上,有点凌乱我的调试和生气与Facebook几个月前!但是它有效。


Possible Duplicate:
Add picture at facebook event with Graph 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.

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.

My latest attempt is over at: http://promos.uk.glam.com/splash_test/example.php

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

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.

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.

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.

Thanks all

解决方案

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:

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

Post:

//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);

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天全站免登陆