Wednesday, September 12, 2012

Fetch Page name from Facebook URL

Question:

Hello! Just started playing with API and GAS!
This is my first, supposed to fetch a Facebook page name if you write in a cell FacebookName(facebookIDpage)

////
// Facebook Page Name
// Made by  iGoogleDrive
// Released as Public Domain
//


function FacebookName(aPageId)
{
    var url = "https://graph.facebook.com/" +(aPageId)+ "?fields=name";

  var response = UrlFetchApp.fetch(url);
  
  var responseText = response.getContentText();
 return responseText;
}


My problem? I get the name, but also the ID, and a lot of oter stuff :

{"name":"I love APERITIVO !","id":"88566307408"}

How can I get just the I love APERITIVO ! without "" in my cell?

I worked it out for the numbers (likes and talking about) but with text information I can't go on!



Solution:

=query(SPLIT(FacebookName(88566307408);char(34));"select Col4")




============
Alternate (updated) Solution:



function FacebookName(aPageId)
{
  var url = "https://graph.facebook.com/" +(aPageId);
  var jsondata = UrlFetchApp.fetch(url);
  var object = Utilities.jsonParse(jsondata.getContentText());
  return object.name;  
}

The above function will return Name of Facebook Page.
============



I hope the above solution will help you, and if you need more help then please do comment below on this blog itself, I will try to help you out.

If this blog post was helpful to you, and if you think you want to help me too and make my this blog survive then please donate here: http://igoogledrive.blogspot.com/2012/09/donate.html 

Thanks,
Kishan,



4 comments:

  1. Thank you that worked!
    is there any options to get it done inside the script? Because since every facebook name changes it is complicated to write in every cell
    Thank you so much :)

    ReplyDelete
    Replies
    1. Hi Irene,

      Yes, it can be done inside the script too...
      I will try to implement it as soon as I get free...

      And if you want it in urgent, then please check out the following link:
      http://igoogledrive.blogspot.in/p/paid-projects.html

      Thanks,
      Kishan.

      Delete
    2. Hi Irene,

      Here is the updated script function:



      function FacebookName(aPageId)
      {
      var url = "https://graph.facebook.com/" +(aPageId);
      var jsondata = UrlFetchApp.fetch(url);
      var object = Utilities.jsonParse(jsondata.getContentText());
      return object.name;
      }

      Delete
  2. Thank you!
    I'd like to share with you a document to see if you can start with a paid project for me, can you give me your gmail since I don't have google + ?

    ReplyDelete