Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to post video to blog #66

Open
gnithin opened this issue Feb 22, 2016 · 10 comments
Open

Not able to post video to blog #66

gnithin opened this issue Feb 22, 2016 · 10 comments

Comments

@gnithin
Copy link

gnithin commented Feb 22, 2016

Hi, I am facing issues with posting a video to Tumblr to my blog.
I've followed the spec from here - https://www.tumblr.com/docs/en/api/v2
I've gone through the issues and most of them are about sharing photos and I couldn't find one relating to video(Let me know if I've left out anything.)
It's working fine when I use a photo, but fails when I use a video.

$this->client->getRequestHandler()->setBaseUrl(TUMBLR_AUTH_BASEURL);
$this->client->setToken($oauth_token, $oauth_token_secret);

// Tried a remote video using source key(Like the remote photo sharing api)
//$video_path = "http://download.wavetlan.com/SVV/Media/HTTP/MP4/ConvertedFiles/Media-Convert/Unsupported/dw11222.mp4";

$video_path = "twitter_sample.mp4";

$file_contents = file_get_contents($video_path);

if($file_contents !== NULL){
    $this->client->getRequesthandler()->setBaseUrl(TUMBLR_BASEURL);
    $data = [
        "type"=> "video",
        "caption" => "posted from API again",
        "source" => $video_path
    ];

    syslog(LOG_WARNING, print_r($data, true));

    $return_vals = $this->client->getRequesthandler()->request(
        "POST",
        "v2/blog/".$blog_identifier.".tumblr.com/post",
        $data
    );

    var_dump($return_vals);

    return $return_vals;
}

It returns -

object(stdClass)[38]
  public 'status' => int 400
  public 'body' => 
    object(Guzzle\Http\EntityBody)[45]
      protected 'contentEncoding' => boolean false
      protected 'rewindFunction' => null
      protected 'stream' => resource(124, stream)
      protected 'size' => null
      protected 'cache' => 
        array (size=9)
          'wrapper_type' => string 'PHP' (length=3)
          'stream_type' => string 'TEMP' (length=4)
          'mode' => string 'w+b' (length=3)
          'unread_bytes' => int 0
          'seekable' => boolean true
          'uri' => string 'php://temp' (length=10)
          'is_local' => boolean true
          'is_readable' => boolean true
          'is_writable' => boolean true
      protected 'customData' => 
        array (size=0)
          empty
  public 'headers' => 
    array (size=7)
      'Server' => 
        array (size=1)
          0 => string 'nginx' (length=5)
      'Date' => 
        array (size=1)
          0 => string 'Mon, 22 Feb 2016 12:42:09 GMT' (length=29)
      'Content-Type' => 
        array (size=1)
          0 => string 'application/json; charset=utf-8' (length=31)
      'Transfer-Encoding' => 
        array (size=1)
          0 => string 'chunked' (length=7)
      'Connection' => 
        array (size=1)
          0 => string 'close' (length=5)
      'Set-Cookie' => 
        array (size=1)
          0 => string 'tmgioct=56cb02215321710025097480; expires=Thu, 19-Feb-2026 12:42:09 GMT; Max-Age=315360000; path=/; httponly' (length=108)
      'P3P' => 
        array (size=1)
          0 => string 'CP="Tumblr's privacy policy is available here: https://www.tumblr.com/policy/en/privacy"' (length=88)

The only error returned is 400 and nothing shows up on the blog.
Using createPost() on this also yields -

Fatal error: Uncaught Tumblr\API\RequestException: [400]: Bad Request (No video data found.) thrown in /exposure-server/src/frontend/vendor/tumblr/tumblr/lib/Tumblr/API/Client.php on line 427

which I guess is the same thing as the previous request.
Is this library not designed for video sharing yet, is there any other way that would work?

@gnithin
Copy link
Author

gnithin commented Mar 16, 2016

I figured out why it was happening -
My main goal was to ultimately share a video from a remote url. Hence using source key for a local video like the one in the example above didn't workout. The solution was to use data and give it the path to the local video.
The Tumblr API documentation requires data key to be assigned to the file contents.
So, when using the data key, the library tries to load the local video using Guzzle(Which gave a lot of errors when used in my production env - Google app engine). Giving it a remote url doesn't work since the file path is checked.
I couldn't find a way to simply add the contents of a file to the data key like the way in the API.
It would be nice if there was a way to stop the data key from being pre-processed and simply accept whatever is given.

@ravi2shah
Copy link

@gnithin have you able to upload a video?
instead of video if I'll upload photo with same code its working fine.

$post_data = array('type' => 'video', 'caption' => 'hello video','data' => $video_path);
$createPost = $tumblr->createPost($unique_id,$post_data);

getting this error while uploading
Tumblr\API\RequestException: [400]: Bad Request (You may only upload one video per post.)

@gnithin
Copy link
Author

gnithin commented Jun 6, 2017

@ravi2shah
Since I was having trouble setting the file content to "data" key on my own, I switched to using another library (this one), where I could just do -

$this->client->oauth_post(
    "/blog/".$blog_identifier.".tumblr.com/post",
    [
        "type"    => "video",
        "caption" => $caption,
        "data"    => file_get_contents($video_path);
    ];
);

It worked back then. I don't know if this would still work, but you can give it a try :)

@ravimisra
Copy link

ravimisra commented Feb 14, 2018

@ravi2shah and @gnithin
I had fixed the issue in this pull request, please pull these changes into your code.

@grzegorz-pierzakowski
Copy link

Hi there,
when are you going to merge this?
Thanks

@DhirajBelure
Copy link

DhirajBelure commented Jun 27, 2018

below parameter require to post video on tumblr
$params = array('type' => 'video','caption' => 'caption','embed'=> '<iframe width="560" height="315" src="your youtube video url" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>');

@ravimisra
Copy link

@DhirajBelure embed option will work only if your video URL is streamable i.e. hosted on Youtube, s3 or on the other video hosting services. It merely embeds your video on your Tumblr blog, instead of uploading the video to Tumblr.

@UVLabs
Copy link

UVLabs commented Aug 24, 2018

@ravimisra @DhirajBelure @grzegorz-pierzakowski @ravi2shah @gnithin you can use embed with HTML5 embed code:

$params = array('type' => 'video','caption' => 'caption','embed'=> '<video width="100%" height="auto" controls><source src="video source on server" type="video/mp4">
Your browser does not support the video tag.
</video>');

@himanshupatel95
Copy link

video not upload .
$video_file = getenv("HOME") . "../video.mp4";

$client = new Tumblr\API\Client(CONSUMER_KEY, CONSUMER_SECRET);
$client->setToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$post_data = ["type" => "video", "caption" => "this is a test video", "data" => $video_file];

try {
print_r($client->createPost(BLOG, $post_data));
} catch (Exception $ex) {
print_r($ex);
}
any Solution ?

@wle1036
Copy link

wle1036 commented Dec 25, 2020

	$arrMessage = array(
					'type' => 'video',
					'tags' => 'test-salam-ok',
					'caption' => 'Photo details',
					'slug' => 'test',
					"data"    =>  $file_url,
					'format' => 'html'
				);

is work God .
data is direct video url like this :

https://wle.ir/downloads/video/cncPaiting.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants