Facebook Webforms应用程序获取app_data查询字符串 [英] Facebook webforms app get app_data querystring
问题描述
如何从Facebook Webforms应用程序获取app_data查询字符串? 我希望能够在querystring中发送一些信息,以便我可以在我的应用程序上显示其他主屏幕. 该应用程序位于页面标签中.
How do i get app_data querystring from a Facebook webforms app? I want to be able to send some info in the querystring so i can display different home screen on my app. The app is sittin in a page tab.
示例: http://www.facebook.com/pages/APPNAME/157772164271503?sk = app_230501256972470& app_data = Page.aspx
如何从app_data获取"Page.aspx"? 我需要它将用户重定向到Default.aspx
How do i get "Page.aspx" from app_data? I need it to redirect the user to a different page from Default.aspx
I found the solution. Get Querystring from facebook tab app using asp.net
using Newtonsoft.Json.Linq;
using System.Text;
public partial class Page_Default : System.Web.UI.Page
{
protected string output = "";
protected void Page_Load(object sender, EventArgs e)
{
output = "Whole thing:" +Request.Form["signed_request"];
output += "Second part:" + Request.Form["signed_request"].Split('.')[1];
try
{
string payload = Request.Form["signed_request"].Split('.')[1];
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, '='));
var json = encoding.GetString(base64JsonArray);
var o = JObject.Parse(json);
output += "Decoded:" + json;
bool liked = (bool)o.SelectToken("page.liked");
output += "Liked:" + liked.ToString();
}
catch (Exception ex)
{
output += "Extract failed: " + ex.Message;
}
}
}
也这篇文章很有帮助
请务必在Facebook应用设置ex中添加直接页面. www.site.com/deafult.aspx不是www.site.com
just be shure to add the direct page in facebook app settings ex. www.site.com/deafult.aspx not www.site.com
推荐答案
在facebook发布的JSON数组中,顶级密钥之一是"app_data"(如果已指定).因此,您可以像对喜欢的"所做的那样进行操作,但是它不是"page.liked",而是"app_data"(而不是布尔值)
In the JSON array that facebook posts, one of the top level keys is 'app_data', if it's specified. So you can to it just as you did for 'liked' but instead of 'page.liked' it would just be 'app_data' (and not a boolean)
这篇关于Facebook Webforms应用程序获取app_data查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!