Google+ Plus API定义特定的图像变量

时间:2012-02-05 08:21:09

标签: php api

我正在尝试将Google+ API集成到我的网站上,以便当用户通过Oauth提交批准时,将会显示其Google+活动供稿。

我的所有工作都非常有用,我正在努力定义它们为其Feed显示的变量。

目前,这就是我的工作:

$activityMarkup = '';
foreach($activities['items'] as $activity) { 

$url = filter_var($activity['url'], FILTER_VALIDATE_URL);
$title = filter_var($activity['title'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
$content = filter_var($activity['object']['content'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
$published = $activity['published'];
$totalItems = $activity['object']['plusoners']['totalItems'];


$activityMarkup .= "<div class='activity'>
        <a href='".$url."' target='_blank'>$title</a>
        <div>$content</div>
        <div><br/><span>Date Published: </span>$published</div>
        <div><br/><span>Total Likes: </span>$totalItems</div>
        </div><br/><br>";

我想要开始工作的是添加与帖子相关联的图片,即缩略图。

我尝试了基于使用现有代码的不同变体,但我无法理解。

根据Google API,这是该图片的信息:

object.attachments [] .image object照片或视频的预览图像 object.attachments []。image.url string链接的URL。

如果上述信息不足,可以使用以下链接指向所有可用的活动:

https://developers.google.com/+/api/latest/activities#object.originalContent

如果有人可以帮我弄清楚如何为图像定义变量,那就太棒了。

我明白了。如果有人需要它,这是代码。

$image=''; 
if(isset($activity['object']['attachments'])){ 
foreach($activity['object']['attachments'] as $att){ 
if(isset($att['image']['url'])) { 
$src = $att['image']['url']; 

要喊出来:

<img src='$src'>

2 个答案:

答案 0 :(得分:0)

   <?php 
   $image=''; 
    if(isset($activity['object']['attachments']))
    { 
            foreach($activity['object']['attachments'] as $att)
            { 
                if(isset($att['image']['url'])) 
                { 
                $src = $att['image']['url'] ;
                }
            }

    }
    ?>        


   <img src='<?php echo $src ?>'> 

工作待遇 - https://developers.google.com/+/api/latest/activities#object.originalContent

答案 1 :(得分:0)

<?php foreach($activities['items'] as $activity): ?>
<div class="activity" >
    <div class="title" ><a href="<?php echo($activity['object']['url']) ; ?>" ><?php echo($activity['object']['content']); ?></a></div>
    <p>Published at <?php echo($activity['published']); ?></p>
    <p>
        <?php echo($activity['object']['replies']['totalItems']); ?> Replys . 
        <?php echo($activity['object']['plusoners']['totalItems']); ?> Plusoners . 
        <?php echo($activity['object']['resharers']['totalItems']); ?> Reshares
    </p>
</div>
<?php endforeach ?>

添加到Feed的另一种方法是回复,加上反复和转发