Git Product home page Git Product logo

Comments (20)

teo1978 avatar teo1978 commented on August 23, 2024 2

So is there a fucking solution after 6 years??

from zendgdata.

deviantmoney avatar deviantmoney commented on August 23, 2024 1

God. Last time I ever use this incomplete shitty framework.

from zendgdata.

steffenweber avatar steffenweber commented on August 23, 2024

I have the same problem: http://framework.zend.com/issues/browse/ZF2-559

from zendgdata.

gullij avatar gullij commented on August 23, 2024

I can verify this as well, there's no setRawData() method in \Zend\HttpClient or the parent class \Zend\Http\Client

from zendgdata.

rcknr avatar rcknr commented on August 23, 2024

Can you try to replace setRawDataStream method in HttpClient.php with the following code and check if it works?

public function setRawDataStream($data, $enctype = null)
{
    $this->_streamingRequest = true;
    if($enctype) $this->setEncType($enctype);
    return $this->setRawBody($data);
}

from zendgdata.

gullij avatar gullij commented on August 23, 2024

@rcknr Using this to upload a file this gives a new error:

strlen() expects parameter 1 to be string, object given (2) at line 1082 in /vendor/zendframework/zendframework/library/Zend/Http/Client.php

from zendgdata.

rcknr avatar rcknr commented on August 23, 2024

@gullij Then try this:

public function setRawDataStream($data, $enctype = null)
{
    $this->_streamingRequest = true;
    if($enctype) $this->setEncType($enctype);
    return $this->setRawBody($data->_fileHandle);
}

from zendgdata.

gullij avatar gullij commented on August 23, 2024

That gives this:

PHP Fatal error: Cannot access protected property ZendGData\MediaMimeStream::$_fileHandle in /vendor/zendframework/zendgdata/library/ZendGData/HttpClient.php on line 347

There's no getter for $_fileHandle in MediaMimeStream so I tested adding that but that creates this error:

PHP Fatal error: Call to a member function read() on a non-object in /vendor/zendframework/zendgdata/library/ZendGData/HttpAdapterStreamingSocket.php on line 83

from zendgdata.

rcknr avatar rcknr commented on August 23, 2024

@gullij It would be great if you show me your code :) It seems like zf2 can handle stream uploads itself if you give it a file handle instead of MediaMimeStream object as a body of the request.
ZF2 documentation is obsolete and still suggests setRawData for such cases.

from zendgdata.

gullij avatar gullij commented on August 23, 2024

I was just about to suggest I give you my code, it's really just the ZF1 example code updated towards ZF2 so if the documentation is obsolete I might be doing something wrong in this

<?php
/**
 * Direct uploading of movies to YouTube
 */

$youTubeAPIKey = "API_KEY";
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
$username = 'USERNAME';
$password = 'KEYWORD';
$file = 'FULL_FILE_PATH';

require 'vendor/autoload.php';

try {

    // TODO: Fix to avoid "sslcapath" exception - something that should be fixed in later version.
    // The client is created only to set the sslcapath option, it isn't necessary to create the client in most cases.
    $client = new \ZendGData\HttpClient();
    $client->setAdapter('Zend\Http\Client\Adapter\Socket');
    $client->getAdapter()->setOptions(array('sslverifypeer' => false));

    $httpClient = \ZendGData\ClientLogin::getHttpClient(
            $username,
            $password,
            $service = 'youtube',
            $client,
            $source = 'UploaderTest', // a short string identifying your application
            $loginToken = null,
            $loginCaptcha = null,
            $authenticationURL);

    $yt = new \ZendGData\YouTube($httpClient, "DirectUpload-0.0.1", "App-Key", $youTubeAPIKey);
    $videoEntry = new \ZendGData\YouTube\VideoEntry();

    // Add file
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $mimeType = $finfo->file($file);
    $filesource = $yt->newMediaFileSource($file);
    $filesource->setContentType($mimeType);
    $filesource->setSlug(basename($file));

    $videoEntry->setMediaSource($filesource);
    $videoEntry->setVideoTitle("Test movie");
    $videoEntry->setVideoDescription("This is a test movie");

    // Make the entry unlisted - only users with the exact path can see it.
    $unlisted = new \ZendGData\App\Extension\Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
    $unlisted->setExtensionAttributes(array(
        array('namespaceUri' => '', 'name' => 'action', 'value' => 'list'),
        array('namespaceUri' => '', 'name' => 'permission', 'value' => 'denied')
    ));
    $videoEntry->setExtensionElements(array($unlisted));

    $videoEntry->setVideoCategory('Autos');
    $videoEntry->setVideoTags('cars, funny');

    // Upload the entry
    $newEntry = $yt->insertEntry($videoEntry, $uploadUrl, '\ZendGData\YouTube\VideoEntry');
    $editUrl = $newEntry->getEditLink()->getHref();
    print "Uploaded: ".$newEntry->getId()." - ".$newEntry->getVideoId()."\n";
} catch (Exception $e) {
    print $e->getMessage()."\n";
    print $e->getTraceAsString()."\n";
}

function out($string)
{
    print $string."\n";
}

from zendgdata.

gullij avatar gullij commented on August 23, 2024

Is there anyone looking into this or has it died off?

from zendgdata.

jamesplewis avatar jamesplewis commented on August 23, 2024

Hi, I'm also looking for a solution to this, thanks.

from zendgdata.

rcknr avatar rcknr commented on August 23, 2024

Agree.

from zendgdata.

gullij avatar gullij commented on August 23, 2024

This seems to be partly fixed, now the returned error is the same as this:
zendframework/zendframework#2645

from zendgdata.

rcknr avatar rcknr commented on August 23, 2024

Agree. You can work with the bare API without using Zend though.

from zendgdata.

rcknr avatar rcknr commented on August 23, 2024

Cool! Don't see Youtube among supported APIs though.
Here you go: https://code.google.com/p/google-api-php-client/source/browse/trunk/src/contrib/Google_YoutubeService.php

from zendgdata.

iBet7o avatar iBet7o commented on August 23, 2024

@gullij Have you solved the problem?

Thanks,

from zendgdata.

gullij avatar gullij commented on August 23, 2024

Sorry, I had forgotten about this.

No, I haven't solved the problem but then again I haven't tested with the latest versions of ZF2 but because the ZendGData component is no longer maintained it's probably not worth spending time on this. Using Google's own is probably the best way to solve this although they have a history of changing their APIs quite often, breaking backwards compatibility.

Their API is here:
https://developers.google.com/youtube/2.0/developers_guide_php

This uses Zend_GData_YouTube from ZF1 so I guess there are a few years until there's a proper PHP 5.3+ version of this.

from zendgdata.

gullij avatar gullij commented on August 23, 2024

Should probably use this client library:
https://developers.google.com/youtube/v3/libraries

from zendgdata.

windy1 avatar windy1 commented on August 23, 2024

Any solutions yet? Google's client library seems incomplete. Can you even do direct uploads with it?

from zendgdata.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.