Scribd API

This is going to my first post. I am currently building a site for checking plagiarism among projects uploaded in my site.

When building a site, i encountered a problem for viewing files of different formats like “.docx”, .”pptx”, “.doc”, “.ppt”, .pdf” and many. First i tried to read contents from a word document (“doc”) which i was able to succeed using anti-word. Then i tried to read contents form “.docx” and then i came to know that “.docx” is a zip and we can read contents from “word/document.xml” using PHP.

PHP has facility to read a .zip file. But in all these cases, i was able to get only the plain text and could display with their formatting. Indeed, i don’t know about and i couldn’t find a solution. Then in web i goggled for “ embedding the files “ in our webpage. Through that i came know about “scribd API” and several other API’s for “embedding the files”.

About Scribd API

I honestly don’t know much about this API. I just saw in http://www.scribd.com/developers how to integrate in our website. For using API, we need to signup for a free API account. After signing up, under the account setting in the API tab look up your “API key” and “API Secret” id.

Second Step:

Now download Scribd.php  from the site. There is a nice tutorial available in scribd developers site also about using scribd. php. Here, i will just say how to upload the doc using scribd API and how to retrieve using javascript.

Uploading a doc using Scribd API:

1) include scribd.php in your php file

2) Create a scribd object using “scribd(api_key,api_secret)”

3) Then use scribd->upload(“filename”,”file_ext”,”access”,”rev_id”);

4) On successful upload scribd API will return “doc_id” and “access_key”

</pre>
<?php

require_once 'scribd.php';
<pre>$api=&quot;API Key&quot;;
$secret=&quot;API Secretj&quot;;

$scribd=new Scribd($api,$secret);</pre>
$api="7fs5j960mfy4seft72lbj";
 $secret="7fs5j960mfy4seft72lbj";

$scribd=new Scribd($api,$secret);
 //Object Created

//print_r($scribd);

$doc_type=$fileExt;
 $access=null;
 $rev_id=null;

$data=$scribd->upload($fileLoc,$doc_type,$access,$rev_id);
<pre>
/* $fileExt - Type of file to be uploaded
	$fileLoc - Completer path of file
*/

?>

5) After uploading $doc will contain an array consisting of “doc_id” and “access_key”.

Note: file Name should be complete. Your PHP version must support curl. Download the latest version of PHP.

Viewing The Uploaded Document:

This is accomplished using the javascript.

Refer http://www.scribd.com/developers/javascript_api and http://www.scribd.com/developers/tutorials to get a clear-cut idea.

My script for reading doc goes here:

<script type="text/javascript">
function GetDoc(doc_id,a_key)
{
	alert(doc_id);
  var scribd_doc = scribd.Document.getDoc(doc_id, a_key);

  var onDocReady = function(e){
     scribd_doc.api.setPage(3);
  }

  scribd_doc.addParam('jsapi_version', 2);
  scribd_doc.addEventListener('docReady', onDocReady);
   scribd_doc.addParam('height', 600);
  scribd_doc.addParam('width', 400);
  scribd_doc.addParam('public', true);
  scribd_doc.write('embedded_doc');
 }
</script>

In my script, when GetDoc(docid,accesskey) is called, the document is written in id called “embedded doc”

Thank you 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s