这是我的脸书页面
当用户单击 Fitbook Contest 第二个选项卡时,它将首先强制用户喜欢一个页面,然后允许使用我的应用程序。但是要访问我的应用程序,首先用户需要允许一个应用程序,然后用户才能访问我的应用程序。
我正在 ac#.net 中进行此编码。这是我的代码。
TestFB.aspx.cs 代码:
public partial class TestFB : System.Web.UI.Page
{
private static string access_token = "";
protected string form_url = "";
public static string FacebookID = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetItemsList();
if (string.IsNullOrEmpty(Convert.ToString(Session["access_token"])))
{
string app_id = "139295982898884";
string app_secret = "b5d2a88b56898610d54da2af498e3220";
string post_login_url = "http://dev.fitbook.com.asp1-23.ord1-1.websitetestlink.com/v4/FitbookContest.aspx";
//string post_login_url = "http://localhost:4327/FitbookContest.aspx";
string scope = "publish_stream,manage_pages";
string code = HttpContext.Current.Request["code"] ?? "";
if (code == "")
{
string dialog_url = "http://www.facebook.com/dialog/oauth?" + "client_id=" + app_id + "&redirect_uri=" + HttpContext.Current.Server.UrlEncode(post_login_url) + "&scope=publish_stream&display=popup";
HttpContext.Current.Response.Redirect(dialog_url);
Response.Write(dialog_url);
}
else
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
app_id, HttpContext.Current.Request.Url.AbsoluteUri, scope, HttpContext.Current.Request["code"].ToString(), app_secret);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string vals = reader.ReadToEnd();
foreach (string token in vals.Split('&'))
{
//meh.aspx?token1=steve&token2=jake&...
tokens.Add(token.Substring(0, token.IndexOf("=")),
token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
access_token = tokens["access_token"];
Session["access_token"] = access_token;
GetProfilePic(code);
}
//Session["ProfileImage"] = imgProfilePicture;
}
}
}
private void GetProfilePic(string code)
{
string accesstoken = Convert.ToString(Session["access_token"]);
var app = new FacebookClient(accesstoken);
var me = (IDictionary<string, object>)app.Get("me");
TestFB.FacebookID = (string)me["id"];
string firstName = (string)me["first_name"];
string lastName = (string)me["last_name"];
string gender = (string)me["gender"];
//Response.Write(me);
string url = "http://graph.facebook.com/" + TestFB.FacebookID + "/picture";
// Response.Write(url);
//Image imgProfilePicture = new Image();
//imgProfilePicture = (Image)HttpContext.Current.Session["ProfileImage"];
imgProfilePicture.ImageUrl = url;
}
}
当我直接访问我的页面时,它与 localhost 和我的服务器一起工作正常。但是当我将服务器路径与“Facebook 页面选项卡”集成时,它不会打开一个弹出窗口并显示空白屏幕。这是我的页面标签应用程序的链接。我正在寻找这样的东西
欢迎提出建议。谢谢你的帮助。