Tumblr API 从 HTML Canvas 发布照片

发布于 2024-12-13 16:31:40 字数 1305 浏览 2 评论 0原文

我在尝试使用代码将 HTML 画布作为照片发布到 Tumblr 时遇到一些问题。我使用的是 PHP,服务器端的代码如下:

if(isset($_POST['postphoto']) and $_SESSION['loggedin']) {
    $title = $_POST['title'];
    $caption = $_POST['caption'];
    tags = $_POST['tags'];
    $imageData = $_POST['imageData'];
    $imageData = substr($imageData,strpos($imageData,",")+1);
    $imageData = str_replace(' ','+',$imageData);

    # Set access token
    $tumblr->set_token($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

    $data = array();
    $data['post'] = array(
        'type'   => 'photo',
        'generator' => 'AppName',
        'data'    => $imageData,
        'name'   => $title,
        'caption' => $caption,
        'tags' => $tags
    );

    $response = $tumblr->fetch('http://www.tumblr.com/api/write', $data);

    if($response['successful']) {
        echo "Update successful!<br><br>";
    } else {
       echo "Update failed. {$response[body]}<br><br>";
    }
}

在 JavaScript 端,我有以下内容:

var imgData = canvas.toDataURL("image/png");            
$("#imageData").val(imgData);

imageData 是隐藏的表单类型,所以我只需设置值。然后将整个表单发布到 PHP 端。我已经检查过并且值传递正确(我对 TwitPic 做了类似的事情,它有效,因为它只接受 toDataURL 值,但 Tumblr 给出了很多问题)。

感谢您的帮助! :)

I'm having some issues trying to get my code to post the HTML canvas into Tumblr as a photo. I'm using PHP, and the code on the server side is as follows:

if(isset($_POST['postphoto']) and $_SESSION['loggedin']) {
    $title = $_POST['title'];
    $caption = $_POST['caption'];
    tags = $_POST['tags'];
    $imageData = $_POST['imageData'];
    $imageData = substr($imageData,strpos($imageData,",")+1);
    $imageData = str_replace(' ','+',$imageData);

    # Set access token
    $tumblr->set_token($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

    $data = array();
    $data['post'] = array(
        'type'   => 'photo',
        'generator' => 'AppName',
        'data'    => $imageData,
        'name'   => $title,
        'caption' => $caption,
        'tags' => $tags
    );

    $response = $tumblr->fetch('http://www.tumblr.com/api/write', $data);

    if($response['successful']) {
        echo "Update successful!<br><br>";
    } else {
       echo "Update failed. {$response[body]}<br><br>";
    }
}

On the JavaScript side, I have the following:

var imgData = canvas.toDataURL("image/png");            
$("#imageData").val(imgData);

imageData is of form type hidden so I simply set the value. The entire form is then posted to the PHP side. I have checked and the values are passed correctly (I did a similar thing for TwitPic, it works since it simply takes in the toDataURL value, but Tumblr is giving lots of issue).

Thanks for the help! :)

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

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

发布评论

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

评论(1

玩世 2024-12-20 16:31:40

可能是因为您正在为照片帖子发布标题?
照片帖子没有标题。让我知道当您删除 'name' => 时它是否有效$标题,

It could be because you are posting title to photo posts?
Photo posts don't have title. Let me know if it works when u remove 'name' => $title,.

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