【问题标题】:CurlException failed creating formpost dataCurlException 创建表单发布数据失败
【发布时间】:2013-06-19 19:55:05
【问题描述】:

我正在尝试上传照片,但我没有得到,目标是在我的粉丝页面墙上发布,我不能,所以我决定在我的墙上测试“我/照片”,同样的事情,出现这个错误!

CurlException 创建表单数据失败

这是我的代码,页面“config.php”只包含配置、appid、secret等...

无论如何,我做错了什么?

  $photo = '/imagens/teste.jpg'; // Path to the photo on the local filesystem
  $message = 'Photo upload via the PHP SDK!';

?>
<html>
  <head></head>
  <body>

  <?php
    if($idUsuario) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        // Upload to a user's profile. The photo will be in the
        // first album in the profile. You can also upload to
        // a specific album by using /ALBUM_ID as the path 
        $ret_obj = $facebook->api('/me/photos', 'POST', array(
                                         'access_token'=> $facebook->getAccessToken(),
                                         'source' => '@'.$photo,
                                         'message' => $message
                                         )
                                      );
        echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
        echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl( array(
                       'scope' => 'photo_upload'
                       )); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      // To upload a photo to a user's wall, we need photo_upload  permission
      // We'll use the current URL as the redirect_uri, so we don't
      // need to specify it here.
      $login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

  </body>
</html>

你可以看到这段代码和 dvelopers.facebook 中的相同代码示例进行上传!

【问题讨论】:

    标签: php facebook


    【解决方案1】:

    您必须将真实路径发送到 API。

    变化:

    $photo = '/imagens/teste.jpg';
    

    作者:

    $photo = realpath('/imagens/teste.jpg');
    

    并检查您的路径是否良好。

    【讨论】:

    • 我在这里遇到了同样的问题,添加真实路径后它显示错误“未设置 URL!”
    猜你喜欢
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    相关资源
    最近更新 更多