English 中文(简体)
Getting information about a Facebook Page via API but without a session_key
原标题:

I m going to create a Facebook application which get informations (name and page_url) about Facebook page from his page_id. So i went to the Facebook Wiki and i found this API method which sounds good at first look :

http://wiki.developers.facebook.com/index.php/Pages.getInfo

My only wish was that i wouldn t pass a session_key parameter because i don t want to force the facebook user to install the application. (You know the "allow application" page or popup).

But the description says :

"The session_key parameter is optional. When the session_key parameter is not passed, you can get information only for Pages that have added your application."

So no problem, exactly what i m looking for !

But after a try, i get this error :

"102 The session key was improperly submitted or has reached its timeout. Direct the user to log in again to obtain another key."

Normal, because i don t pass the session_key parameter.

I m using Rails + Facebooker plugin. So i try this methods in my console without success :

>>Facebooker::Session.create.pages(:fields => ["name", "page_url"], :page_ids => "123456")
=> []


>> Facebooker::Session.create.fql_query("SELECT name, page_url FROM page WHERE page_id=123456")
=> []

(of course, the page with page_id="123456" has installed my application)

Someone knows how to get information about a page but without the needed of passing a session_key parameter ?

I know it s possible because i have already saw a facebook application retrieve information about a page without ask user to install his application.

问题回答
private string ToUrlBase64String(byte[] Input)
{
    return Convert.ToBase64String(Input).Replace("=", String.Empty)
                                        .Replace( + ,  - )
                                        .Replace( / ,  _ );
}

private byte[] SignWithHmac(byte[] dataToSign, byte[] keyBody)
{
    using (var hmacAlgorithm = new HMACSHA256(keyBody))
    {
        hmacAlgorithm.ComputeHash(dataToSign);
        return hmacAlgorithm.Hash;
    }
}

#region["Parse Signed_Request Method"]
/// <summary>
/// Parse Signed_Request Method
/// </summary>
/// <param name="signedRequestValue"></param>
/// <returns></returns>
private string ParseSignedRequest(string signedRequestValue)
{
    string PageID = string.Empty;
    string applicationSecret = "7f7e426af4d835a2fd54abea04520283";
    string[] signedRequest = signedRequestValue.ToString().Split( . );
    string expectedSignature = signedRequest[0];
    string payload = signedRequest[1];
    // Attempt to get same hash
    var Hmac = SignWithHmac(UTF8Encoding.UTF8.GetBytes(payload), UTF8Encoding.UTF8.GetBytes(applicationSecret));
    var HmacBase64 = ToUrlBase64String(Hmac);

    if (HmacBase64 != expectedSignature)
        return null;
    var encoding = new UTF8Encoding();
    var decodedJson = payload.Replace("=", string.Empty).Replace( - ,  + ).Replace( _ ,  / );
    var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4,  = ));
    string myvalue = Convert.ToString(JsonConvert.DeserializeObject(encoding.GetString(base64JsonArray)));        
    string ss = myvalue.Replace("{", "").Replace("}", "").Replace(""", "");
    string[] s = ss.Split( , );
    for (int i = 0; i < s.Length; i++)
    {
        string[] s1 = s[i].Split( : );
        if (s1[0].ToString().Trim().ToLower() == "profile_id")
        {
            string[] myapp = s[i].Split( : );
            PageID = myapp[1].ToString().Trim();
        }
    }
    return PageID;

}

#endregion


#region["Page_Load Event"]
/// <summary>
/// Page_Load Event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{

    string SignedRequest = Request.Form["signed_request"].ToString();
    string myvalue = Convert.ToString(ParseSignedRequest(SignedRequest));
    //now myvalue contain the page id      
}
#endregion

This thread on developers.facebook.com could help you http://forum.developers.facebook.com/viewtopic.php?pid=147246#p147246

Okay, after some try out, I can say that the API method "Pages.getInfo" when it called without session_key seems to return ONLY pages already PUBLISHED.

And of course, pages that i want to get information might be UNPUBLISHED... too bad.

Any chance to retrieve a page url from a unpublished page ?





相关问题
Facebook Connect login dialog not working

I am using Facebook Connect for iPhone and following the official instructions. I use the following code to display the login dialog: FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:...

Facebook App Profile Tab is Empty ... No Content Displayed?

I can view my application via the http://apps.facebook.com/myapplication/ link and the content shows up correctly. I also added the application as a tab to a facebook page. However, when viewing the ...

Facebook Platform error: "Object cannot be liked"

I m working on a Facebook Application that generates wall posts. In testing these posts, I ve discovered that the Facebook Platform action of "liking" a post is failing. The specific error message ...

how to call showPermissionsDialog() in php (facebook api)?

I was reading over the documentation yet I could not figure out how to call Facebook.showPermissionsDialog() in php include_once ./facebook-platform/php/facebook.php ; $facebook = new Facebook(my ...

Facebook connect

If I plug in the facebook connect into my website, How can I prevent double signups? Lets say I have a user that s already signed up to my site but he clicked the connect with facebook, is there a ...

热门标签