Curl / PHP Script error "Slideshow file is not a source object"

165 views
Skip to first unread message

Jamie Davies

unread,
Dec 13, 2008, 2:29:08 PM12/13/08
to SlideShare Developers
Hi all,

I'm relatively new to working with the Slide Share API. I am
attempting to write a script that will upload a file (the file name
will eventually be provided by a SQL query but it's hard coded at the
moment) to SlideShare but I'm constantly getting the "Slideshow file
is not a source object" error.

It could be (sure it is) a really obvious error with the code; or it
could be something I'm not even considering.

When it comes to providing the filename I have tried running the
script from the directory with the file, using full file name (eg. /
home/user/htdocs/website/filelocation/powerpoint.ppt) and even URL's
but can't seem to get it to work. Each time I get the error 6:

I have included the code I'm using below.

Any suggestions or just a puch in the right direction would be most
welcomed.

Cheers, Jamie.

<?php
// -------------------------------------------------------
// SlideShareCurlUpload.php
// Upload file to slideshare.net
// -------------------------------------------------------

// Edit User Details
// User API Keys
$api_key = 'xxx';
$sharedsecret = 'zzz';
// Account Information
$username = 'username';
$password = 'password';
// URL for form to be submitted
$url = 'http://www.slideshare.net/api/1/upload_slideshow';

//////////////////////////////////////////////////////////////////////
// Set values needed by CURL to submit to API form
// Set UNIX timestamp variable
$ts = time();
// Concatenate $ts & $sharedsecret
$sha_hash = $ts.$sharedsecret;
// Create SHA1 hash of concatenated variables
$hash = sha1($sha_hash);

// For now - will come from DB
$SlideDetails['filename'] = '11958674511194251558.ppt';
$SlideDetails['title'] = 'test title';

// CURL Paramaters
$params = 'api_key='.$api_key.'&sharedsecret='.
$sharedsecret.'&username='.$username.'&password='.$password.'&ts='.
$ts.'&hash='.$hash.'&slideshow_title='.$SlideDetails
['title'].'&slideshow_srcfile='.$SlideDetails['filename'];
$user_agent = 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)';
$ch = curl_init();
// Do the CURL
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);

// For Debugging
echo $params.'<br />';
echo 'Results:'.$result;

?>

sim

unread,
Dec 14, 2008, 1:55:05 AM12/14/08
to slideshare...@googlegroups.com

Hey,
    Basically i just wanna to get the details of the presentation from slideshare by giving just the url using cURL.Can you give the API for that, i dont need to upload a presentation.

Jamie Davies

unread,
Dec 21, 2008, 5:10:37 AM12/21/08
to SlideShare Developers
I'm still struggling with this if anyone has any thoughts ...

Cheers, Jamie.

Kosso

unread,
Dec 21, 2008, 5:27:44 AM12/21/08
to slideshare...@googlegroups.com
Hi there,

Try this which works for me - and which I use on phreadz.com

$url is the normal full url to the slideshare presentation:


function getSlideShare($url){

    $slideShareApiKey = "YOUR_SLIDESHARE_API_LKEY;
    $slideShareSecret = "YOUR_SLIDESHARE_SECRET_PASSWORD";

    $slideshare = Array();

    $host = "http://www.slideshare.net/api/1/get_slideshow_info";
    $ts = time();
    $hash = sha1($slideShareSecret.$ts);
    $params = array(
        "api_key"=>$slideShareApiKey,
        "ts"=>$ts,
        "hash"=>$hash,
        "slideshow_url"=>$url
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    $reply = curl_exec($ch);
    $replyArray = curl_getinfo($ch);
    curl_close($ch);
    $xml = simplexml_load_string($reply);
    if($xml->Status!="2"){
        logIt("Status not 2");
        return 0;
    }

    $slideshare['id'] = (string)$xml->ID;
    $slideshare['doc'] = (string)$xml->PlayerDoc;
    $slideshare['author'] = (string)$xml->UserLogin;
    $slideshare['tags'] = (string)$xml->Tags;
    $slideshare['title'] = (string)$xml->Title;
    $description = (string)$xml->Description;
    $slideshare['description'] = "a SlideShare presentation by ".$slideshare['author']."\nuser: http://www.slideshare.net/".$slideshare['author']."/\nview: ".$url."\n".$description;
    // get the thumbnail
    $thumbnailUrl = (string)$xml->ThumbnailURL;
    $slideshare['thumbNail'] = $thumbnailUrl."&type=.jpg";
    $slideshare['fileUrl'] = "http://s3.amazonaws.com/slideshare/ssplayer.swf?id=".$slideshare['id']."&doc=".$slideshare['doc'];


    // return an array with all the details you need

    return $slideshare;

}


Hope this helps!

Cheers,
Kosso
Founder : Phreadz.com


2008/12/21 Jamie Davies <jamie...@gmail.com>



--
-------------------------------------------------------
Phreadz : Founder: http://phreadz.com
Phreadz Blog : http://phreadz.blogspot.com
Personal Blog: http://kosso.wordpress.com
Twitter: http://twitter.com/kosso

Jamie Davies

unread,
Dec 21, 2008, 11:00:03 AM12/21/08
to SlideShare Developers
Hi Kosso,

Thanks for the file - I'll definitely use that for getting the
slideshow info (which I haven't got to yet so you've saved me some
coding time).

My problem is with the upload_slideshow API rather than getting the
info after a slide has been uploaded.

Excellent script that you've written though.

Thanks.

Jamie
> 2008/12/21 Jamie Davies <jamiedav...@gmail.com>

Gee Chuang

unread,
Dec 22, 2008, 1:53:05 PM12/22/08
to SlideShare Developers

Hi Jamie,

The upload_slideshow method requires a multipart POST. The
'slideshow_srcfile' parameter therefore is not just a string with the
file's location, but is instead the actual file.

We have written a PHP wrapper that should help:
http://code.google.com/p/slideshare-phpkit/source/browse/trunk/SSUtil.php

Let me know if you have any further questions.

Thanks,
Gee
Reply all
Reply to author
Forward
0 new messages