imgur API将无法正常工作 [英] imgur api won't work

查看:325
本文介绍了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 \\家庭\\ 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

你们能帮助我吗?

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

And yes, i already searched through these topics:

<一个href=\"http://stackoverflow.com/questions/2625422/html-upload-form-will-only-upload-files-found-in-the-directory-of-the-php-file\">HTML上传表单只会上传PHP文件的目录中的文件。结果
<一href=\"http://stackoverflow.com/questions/2616675/using-jquery-to-parse-xml-returned-from-php-script-imgur-com-api\">Using 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天全站免登陆