views:

312

answers:

0

Hi guys I'm trying to upload a document to google docs but I'm getting an error namely an

Unknown authorization header Error 401 

to be exact.. I'm developing for google apps marketplace here - my code for uploading is:

$client = getGoogleClient();
$docs = new Zend_Gdata_Docs($client);
uploadDocument($docs, true, $FILES['file']['name'], $FILES['file']['tmp_name']);

function getGoogleClient()
{
$options = array(
    'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
    'version' => '1.0',
    'signatureMethod' => 'HMAC-SHA1',
    'consumerKey' => $CONSUMER_KEY,
    'consumerSecret' => $CONSUMER_SECRET
);

$consumer = new Zend_Oauth_Consumer($options); 
$token = new Zend_Oauth_Token_Access();
$httpClient = $token->getHttpClient($options);

return $httpClient;
}



function uploadDocument($docs, $html, $originalFileName, $temporaryFileLocation) {
    $fileToUpload = $originalFileName;
    if ($temporaryFileLocation) {
        $fileToUpload = $temporaryFileLocation;
    }

    $newDocumentEntry = $docs->uploadFile($fileToUpload, $originalFileName, null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI); // this function never executes completely I get the error

    $alternateLink = '';
    foreach ($newDocumentEntry->link as $link) {
        if ($link->getRel() === 'alternate') {
          $alternateLink = $link->getHref();
        }
    }
    return $alternateLink;
}

ANy ideas ?