dttwois6098 2014-10-30 11:36
浏览 75
已采纳

Facebook Api - 登录并获取封面图片

i'm currently trying to wrap my head around this as it's my first time using the Facebook API, essentially i just want my php to grab the image link of the users cover photo to display it on a standard php page, i've set it up to display the cover link as text but i'm not getting anything.

I've googled and searched stackoverflow but i can't seem to find anything, here's my current code:-

function statusChangeCallback(response) {
    console.log('statusChangeCallback');
    console.log(response);

    if (response.status === 'connected') {
      testAPI();
    } else if (response.status === 'not_authorized') {
      document.getElementById('status').innerHTML = 'Please log ' +
        'into this app.';
    } else {
      document.getElementById('status').innerHTML = 'Please log ' +
        'into Facebook.';
    }
}


function checkLoginState() {
    FB.getLoginStatus(function(response) {
        statusChangeCallback(response);
    });
}

window.fbAsyncInit = function() {
    FB.init({
        appId      : '000000000000000',
        cookie     : true,
        xfbml      : true, 
        version    : 'v2.1'
    });


    FB.getLoginStatus(function(response) {
        statusChangeCallback(response);
    });
};


(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];

if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


function testAPI() {
console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
        console.log('Successful login for: ' + response.name);
        document.getElementById('status').innerHTML =
        'Thanks for logging in, ' + response.name + '!' +
        response.fields=cover;
    });
}

Any help would be greatly appreciated

  • 写回答

1条回答 默认 最新

  • drxpt06820 2014-11-03 11:47
    关注

    Turns out Facebook depreciated the Username reference for the API, so there's no specific way to do it through the API or through the graph.

    The only way i managed to do it is by creating an input field for them to generate their content from the username they put in, thanks anyway guys

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题