简体   繁体   English

如何从Facebook图形响应中获取图像的URL?

[英]How to get URL of the image from Facebook graph response?

I'm trying to create a Facebook wall feed for an mobile app using Ionic/AngularJS framework. 我正在尝试使用Ionic / AngularJS框架为移动应用程序创建Facebook墙供稿。 I need help to retrieve the direct image link of an published photo at my fanpage. 我需要帮助才能在我的粉丝专页上检索已发布照片的直接图像链接。 The picture object from the JSON data display an very small thumbnail of the original photo so if I increase the size using CSS it losses the quality.I am using the link value URL as img ng-src but doesnt display anything since the link is not to the image itself but the link to the post on facebook. JSON数据中的picture对象显示的是原始照片的非常小的缩略图,因此如果我使用CSS增大尺寸,则会失去质量。我将链接值URL用作img ng-src,但未显示任何内容,因为该链接没有图片本身,但指向Facebook上帖子的链接。

Below are my codes, Inside view: 以下是我的代码,内部视图:

<ion-content padding="true" ng-controller="FacebookCtrl" class="has-footer">
           <label class="item item-input">
                <i class="icon ion-search placeholder-icon"></i>
                <input type="text" placeholder="Search..." ng-model="query" >
            </label>
            <ion-list ng-repeat="item in news | filter:query | limitTo:20">
           <ion-item  ng-if="item.type == 'photo'">
               <h2 >{{item.caption}}</h2>
               <p>{{item.message}}</p>
               <img ng-src="{{item.link}}"/><br>
               <i class="icon ion-android-favorite"></i> {{item.likes.data.length}} Pelqime
               <p>Publikuar me: {{item.created_time | date: 'medium' }}  </p>
           </ion-item>
           <ion-item  ng-if="item.type == 'link'">
               <h2 >{{item.name}}</h2>
               <p>{{item.message}}</p>
                    <img ng-src="{{item.picture}}"/><br>
               <i class="icon ion-android-favorite"></i> {{item.likes.data.length}} Pelqime
               <p>Publikuar me: {{item.created_time | date: 'medium' }}  </p>
           </ion-item>
           <ion-item  ng-if="item.type == 'video'">
               <h2 >{{item.name}}</h2>
               <p>{{item.message}}<br>
                    {{item.source}}
               </p>
               <video width="400" controls src="{{item.source}}">Your browser does not support HTML5 video.
               </video>

               <i class="icon ion-android-favorite"></i> {{item.likes.data.length}} Pelqime
               <p>Publikuar me: {{item.created_time | date: 'medium' }}  </p>
           </ion-item>
           </ion-list>

        </ion-content>

Controller: 控制器:

.controller('FacebookCtrl',function($scope,$http){
    $http.get('https://graph.facebook.com/radioopendimi/feed?access_token=APP_ID|APP_Secret').then(function(resp){
        $scope.news = resp.data.data;
        console.log('Success: ',resp);
    }, function(err){
        console.error('Error: ',err);
    });

});

Request the field full_picture , that should contain the largest version of the image that Facebook has available. 请求字段full_picture ,该字段应包含Facebook可用的图像的最大版本。

https://graph.facebook.com/radioopendimi/feed?fields=full_picture,[…]&access_token=…

Be aware that when using the fields parameter, you must specify all fields you want to get, otherwise you will only get the id by default. 请注意,使用fields参数时,必须指定要获取的所有字段,否则默认情况下将仅获取id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM