あなたのプロジェクトの種類は何ですか: WinForms、WPF、ASP.NET ?
WinFormsまたはWPFを使用している場合は、OAuth ログイン ダイアログと をリクエストしてaccess_token
フォームのURLを取得し、URL から有効なものを抽出する必要があります。Browser Control
return_type=token
access_token
それ以外の場合、ASP.NETを使用して Web アプリケーションで作業している場合は、ユーザーを OAuth ダイアログ ログイン ページにリダイレクトする必要があります。その後、Facebook が URL のコードを使用してリダイレクトしますQueryString
。HTTPRequest
Facebook にアクセスして、有効な を取得しますaccess_token
。
あなたはそれを行うために私の方法を使うことができます:
public string GetAccessTokenFromCode(string AppID, string AppSecret, string RedirectURL, string Code)
{
WebClient wc = new WebClient();
string u2 = "https://graph.facebook.com/oauth/access_token?client_id=" + AppID + "&redirect_uri=" + RedirectURL + "&client_secret=" + AppSecret + "&code=" + Code + "&state=anytexthere";
string access = wc.DownloadString(u2);
access = access.Substring(access.IndexOf("access_token") + 13);
if (access.Contains("&"))
{
string accesstoken = access.Substring(0, access.IndexOf("&"));
return accesstoken;
}
return access;
}
から呼び出すことができますPage_Load
:
if (Request.QueryString["code"] != null)
{
code = Request.QueryString["code"].ToString();
string AT = GetAccessTokenFromCode(AppID, AppSecret, RedirectUrl, Code);
}