Welcome Guest, Not a member yet? Register   Sign In
Adjusting data structure?
#1

[eluser]flokky[/eluser]
I'm trying to use the Zend Gdata framework to access YouTube. This is working great. The only thing I'm having problem with, is how I can change or alter the structure of the data being returned by the YouTube service.

I have a piece of code that searches for all videos uploaded by the given user:
Code:
function getAllUserUploads($userName) {    
    $yt = new Zend_Gdata_YouTube();
    return printVideoFeed($yt->getuserUploads($userName));
}

I iterate over all found videos and call 'printVideoEntry' for printing out the video-properties :
Code:
function printVideoFeed($videoFeed) {
    foreach ($videoFeed as $videoEntry) {
        printVideoEntry($videoEntry);
    }
    return $videoFeed;
}

What I would like to do: I would like to adjust the $videoEntry->getVideoId() and append HTML to that property, so I can easily print out a YouTube player....
Code:
function printVideoEntry($videoEntry) {
    ...
    $videoEntry->getVideoId() = createEmbedTagCode($videoEntry->getVideoId())
    ...
}

... but this results in an error:
Code:
Fatal error: Can't use method return value in write context ...

How can I use the setter of the $videoEntry object so I can alter videoId?
#2

[eluser]TheFuzzy0ne[/eluser]
You cannot set a function using the = sign.

Code:
$videoEntry->getVideoId() = createEmbedTagCode($videoEntry->getVideoId())

should probably read something like:

Code:
$videoEntry->getVideoId(createEmbedTagCode($videoEntry->getVideoId()));

Hope this helps.

EDIT:

Alternatively it could be something like:

Code:
$videoEntry->getVideoId = createEmbedTagCode($videoEntry->getVideoId());
#3

[eluser]flokky[/eluser]
Hi FuzzyOne, Thanks for helping out.

You are right, by changing it to the code you suggest, the error goes away.

Code:
$videoEntry->getVideoId(createEmbedTagCode($videoEntry->getVideoId()));

But when I do a print out of the video id, it's the same. Just like it was before the call to 'createEmbedTagCode'.

Code:
print_r($videoEntry->getVideoId());

I can't see what I'm missing here?

By the way: your alternatively piece of code gives errors from the Zend Framework

Code:
$videoEntry->getVideoId = createEmbedTagCode($videoEntry->getVideoId());

Code:
Fatal error: Uncaught exception 'Zend_Gdata_App_InvalidArgumentException' with message 'Property _getVideoId does not exist'
#4

[eluser]TheFuzzy0ne[/eluser]
I'd imagine that it's because we're trying to set through a getter function. I can't be more specific as I don't use Zend GData.

Find what variable getVideoId() sets, and see if you can alter that directory, (if it's not private). Be warned, however, your library may not take kindly to that level of tinkering. I'd image that the ID should be numeric, or some other specific format, and probably shouldn't contain any HTML.




Theme © iAndrew 2016 - Forum software by © MyBB