Glass Mirror API save attatchment image to server via PHP -
i using php quick start project example display timeline's attachment (image):
<?php if ($timeline_item->getattachments() != null) { $attachments = $timeline_item->getattachments(); foreach ($attachments $attachment) { ?> <img src="<?php echo $base_url . '/attachment-proxy.php?timeline_item_id=' . $timeline_item->getid() . '&attachment_id=' . $attachment->getid() ?>" /> <?php } } ?>
now need save image server can resize , use elsewhere. have tried few variations of file_put_contents, fopen, , curl seems attachment-proxy.php not returning image in format of these expect.
how can save timeline attachment server?
solution: based on prisoner's response took @ attachment-proxy.php file. returning image string. had unsuccessfully tried file_put_contents($img, file_get_contents("attachment-proxy.php....")); before. turns out don't need file_get_contents() part. altered last few lines of attachment-proxy.php this:
$img = $_get['timeline_item_id'].'.jpg'; $image = download_attachment($_get['timeline_item_id'], $attachment); file_put_contents($img, $image);
it works. saves image server id file name. thanks.
have checked see is returning? attachment_proxy.php requires oauth have been completed, , redirect through oauth flow if hasn't been done. may saving html oauth login page, or information redirect page.
however, if you're trying setup on server calls own server's attachment_proxy.php page... you're jumping through additional unnecessary hoops.
you can take directly @ attachment_proxy.php see how getting attachment data google's servers, , use same method them , store them on server instead of feeding out img tag. looking @ https://github.com/googleglass/mirror-quickstart-php/blob/master/attachment-proxy.php seems of work done in call download_attachments()
located in https://github.com/googleglass/mirror-quickstart-php/blob/master/mirror-client.php. should able either borrow code download_attachments()
or call directly yourself.
Comments
Post a Comment