Facebook API Javascript JSON response

前端 未结 3 2071
执笔经年
执笔经年 2021-02-06 17:48
function getUser()
{
    FB.api(\'/me\', function(response) {
       console.log(\'Response is \'+response);
       alert(\'Your name is \' + response.first_name);
              


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 18:20

    Use Jquery get Json method isted using pure javascript,

    1. You need to get Accesstoken
    2. Replace your access token below the texted YOUR_ACCESS_TOKEN field

    I used this library to get the date formatted, https://github.com/datejs/Datejs

        $.getJSON("https://graph.facebook.com/5973249561/events/?access_token=YOUR_ACCESS_TOKEN&fields=id,name,description,start_time,place,cover,end_time&limit=4",
          function(result){
            for(x = 0; x < result.data.length; x++) {
              var id = result.data[x].id;
              var name = result.data[x].name;
              var cover = result.data[x].cover.source;
              var date = new Date(result.data[x].start_time);
              var place = result.data[x].place.name;
              var day = date.toString('dd');
              var month = date.toString('MMM');
              var url = 'https://facebook.com/'+id;
              var time = date.toString("hh:mm tt");
              $("#evt").append(name);
            }
          });
    

提交回复
热议问题