使用 Facebook PHP SDK:未捕获的 CurlException:26:无法创建 formpost 数据 [英] Working with Facebook PHP SDK: Uncaught CurlException: 26: failed creating formpost dat

查看:23
本文介绍了使用 Facebook PHP SDK:未捕获的 CurlException:26:无法创建 formpost 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了一些关于此错误消息的 stackoverflow 帖子,但没有一个对我有用.

I had a look at several stackoverflow posts about this error message, but none of them worked for me.

我想上传照片到脸书:

public function uploadPhoto($path){
    $photoSettings = array(
        'access_token'=> $this->facebook->getAccessToken(),
        'name' => 'uploaded foto',
        'source' => '@' . realpath($path)
    );

    $photo = $this->facebook->api('me/photos','POST',$photoSettings);
}

当我调用这个函数时,我收到以下错误信息:

When i call this function, i get the following error message:

未捕获的 CurlException:26:创建表单数据失败

Uncaught CurlException: 26: failed creating formpost data

我 100% 确定我要上传的图像存在(并且路径正确).

I am 100% sure that the image i want to upload exists (and the path is correct).

这是我的 facebook 初始化:(fileUpload 为 true)

This is my facebook initialization: (fileUpload is true)

$this->facebook = new Facebook(array(
          'appId'  => $this->config['appId'],
          'secret' => $this->config['appSecret'],
          'fileUpload' => true,
          'cookie' => true
    ));

我真的不明白为什么我会收到那个错误,因为我的代码似乎是正确的.您认为我的服务器/服务器的 cURL 配置可能有问题吗?我对 cURL 了解不多.

I really don't understand why i get that error because my code seems to be correct. Do you think there could be a problem with my server / the server's cURL configuration? I dont know much about cURL.

希望你能帮帮我!我期待着你的回答:-)

I hope you can help me! I am looking forward for your answers :-)

您好,安德烈亚斯

推荐答案

I kept getting "CurlException: 26: failed creating formpost data" 

Here is my working code for uploading a photo from the same directory as the PHP page communicating with   Facebook:
$facebook    =  new Facebook(array(
'appId'      =>'*****',
'secret'     =>'*******',
'fileUpload' => true,
'cookie'     => true
));
 $user  =   $facebook ->getUser();
 if($user) 
 {  
$facebook->setFileUploadSupport(true);
$args = array(
    'message' => 'TEst from App.',
    'image' => '@' . realpath('awesome.jpeg')
);
try {
    $data = $facebook->api('/me/photos', 'post', $args);
} catch(FacebookApiException $e) {
    echo "ERROR: " . $e;
}

 }

这篇关于使用 Facebook PHP SDK:未捕获的 CurlException:26:无法创建 formpost 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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