Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 回显json代码的一部分_Php_Json_Echo - Fatal编程技术网

Php 回显json代码的一部分

Php 回显json代码的一部分,php,json,echo,Php,Json,Echo,我正在使用imgurapi上传一个图像,然后我想回显图像的链接。 代码如下: <?php $client_id = 'xxxxxxxxxxx'; $file = file_get_contents("http://mywebsite.com/image.jpeg"); $url = 'https://api.imgur.com/3/image.json'; $headers = array( "Authorization: Client-ID $client_id" )

我正在使用imgurapi上传一个图像,然后我想回显图像的链接。 代码如下:

<?php
$client_id = 'xxxxxxxxxxx';

$file = file_get_contents("http://mywebsite.com/image.jpeg");

$url     = 'https://api.imgur.com/3/image.json';
$headers = array(
    "Authorization: Client-ID $client_id"
);
$pvars   = array(
    'image' => base64_encode($file)
);

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_POST => 1,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POSTFIELDS => $pvars
));

$json_returned = curl_exec($curl); // blank response


echo $json_returned;
curl_close($curl);

?>

如何仅回显图像的url?

Imgur要求通过HTTPs访问API

查看如何使用认证文件

您还可以禁用“直通检查”选项(不推荐!):

然后,要访问链接,只需使用:

$json_returned = json_decode($json_returned, true);
echo $json_returned['data']['link'];

echo json\u decode($json\u returned,true)['data']['link']
@Dave Chen我试过使用echo json\u decode($json\u returned,true)['data']['link'],但是输出是一个空白页。你能帮我吗?对不起,我是在一瞬间写的。您需要先对其进行解码,然后读取数组索引。例如
$json\u returned=json\u decode($json\u returned,true);echo$json_返回['data']['link']
@DaveChen输出仍然是一个空白页。这是全部代码。请随意测试并找出错误。谢谢!
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0
$json_returned = json_decode($json_returned, true);
echo $json_returned['data']['link'];