【问题标题】:How to get link from object returned by imgur api如何从 imgur api 返回的对象中获取链接
【发布时间】:2015-07-28 00:18:59
【问题描述】:

我正在使用: 1.Laravel 5 2.https://github.com/MarkRedeman/Imgur-Laravel

我的控制器:

public function store()
    {
        $input = Request::all();

        $upload = new Upload($input);

        $upload->save();

        $upload_id = $upload->id;

        $path =  $this->resizeAndSaveTempImage($upload->raw_image_url);

        $done = $this->uploadToImgur($path);

        dd($done);



    }

public function resizeAndSaveTempImage($image_url)
    {


        $img = Image::make($image_url)->insert('http://i.imgur.com/Ned0D1ub.jpg', 'top', 130, 330);

        $tmp_name = 'final-output-' . microtime(true) . '.jpg';

        $path = 'tmp/' . $tmp_name;

        $img->save($path);

        return $path;



    }

    public function uploadToImgur($image_path)
    {
        $imageData = array(
            'image' => $image_path,
            'type'  => 'file',
            'name' => 'Lipsum',
            'title' => 'Lorem Ipsum',
            'description' => 'Lorem Ipsum Dolor Sit Amet'
        );

        $basic = Imgur::api('image')->upload($imageData);

        return $basic;
    }

die 和 dump 的结果:

Basic {#236 ▼
  -data: array:20 [▼
    "id" => "KWIhRsS"
    "title" => "Lorem Ipsum"
    "description" => "Lorem Ipsum Dolor Sit Amet"
    "datetime" => 1431732751
    "type" => "image/jpeg"
    "animated" => false
    "width" => 640
    "height" => 640
    "size" => 95601
    "views" => 0
    "bandwidth" => 0
    "vote" => null
    "favorite" => false
    "nsfw" => null
    "section" => null
    "account_url" => null
    "account_id" => 0
    "deletehash" => "z8M21wNHdsFOBhJ"
    "name" => "Lipsum"
    "link" => "http://i.imgur.com/KWIhRsS.jpg"
  ]
  -success: true
  -status: 200
}

但如果我尝试访问链接

dd($done->data['link']);

它给了我这个错误:

Cannot access private property Imgur\Api\Model\Basic::$data

如何从响应对象访问链接?

【问题讨论】:

    标签: php laravel imgur


    【解决方案1】:

    在此处调查代码后:

    https://github.com/Adyg/php-imgur-api-client/blob/master/lib/Imgur/Api/Model/Basic.php

    我使用的包扩展了,返回对象的 $data 属性存在一个 getter。

    $done->getData() 
    

    【讨论】:

      猜你喜欢
      • 2011-08-10
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      • 2017-03-18
      相关资源
      最近更新 更多