imgur api 不起作用 [英] imgur api won't work

查看:42
本文介绍了imgur api 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 imgur api 的问题.我想使用 imgur api 为我的网站创建一个图库,但是我如何创建一个上传到 imgur 服务器的文件上传器?

i have a question about the imgur api. I want to create a gallery for my website using the imgur api, but how can i create a file uploader that uploads to the imgur servers?

这是我创建的:

<?php
include 'xmlparser.php'; // From http://www.criticaldevelopment.net/xml/doc.php
if($_SERVER['REQUEST_METHOD'] == "POST"){
    $data = file_get_contents($_FILES["file"]['tmp_name']);

    // $data is file data
    $pvars   = array('image' => base64_encode($data), 'key' => HERE_MY_API_KEY);
    $timeout = 30;
    $curl    = curl_init();

    curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.xml');
    curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);

    $xml = curl_exec($curl);

    $parser = new XMLParser($xml);
    $parser->Parse();
    echo $parser->images->item->links->original;

    curl_close ($curl); 
}
else
{
    ?>
    <form action="test.php" method="post" enctype="multipart/form-data">
        <input type="file" name="file" id="file" /> 
        <input type="submit" name="submit" value="Submit" />
    </form>
    <?php
} 
?>

但这似乎不起作用...?我收到此错误:

But this doesn't seem to work...? I get this error:

解析错误:语法错误,意外的 T_STRING,在 C:\data\home\www\test.php 中第 7 行需要 ')'

Parse error: syntax error, unexpected T_STRING, expecting ')' in C:\data\home\www\test.php on line 7

第 7 行是这一行:

$pvars   = array('image' => base64_encode($data), 'key' => HERE_MY_API_KEY);

怎么了?imgur api 的文档在这里:http://api.imgur.com/examples

What is wrong? The documentation of the imgur api is here: http://api.imgur.com/examples

你们能帮帮我吗?

是的,我已经搜索了这些主题:

And yes, i already searched through these topics:

HTML 上传表单只会上传在 PHP 文件目录中找到的文件
使用jQuery解析PHP返回的XML脚本(imgur.com API)

但这对我没有帮助...

But it didn't help me...

问候

推荐答案

将 API 密钥放在引号中.他们把它放在所有大写字母和引号外的方式是表示一个常数值.

Put the API key in quote marks. The way they put it in all caps and outside quote marks is to signify a constant value.

这篇关于imgur api 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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