我必须检索C#软件的SID才能将其与Facebook连接。
我看到我必须打印这个:
string sid=WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();
但是写的是WebAuthenticationBroker
在上下文中不存在。
所以我添加了using Windows.Security.Authentication.Web;
但它仍然不起作用。
你有一些解决方案吗?
这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Facebook;
using System.Net;
using System.Web;
using System.Dynamic;
using Windows;
using Windows.Security.Authentication.Web;
namespace testfb
{
public partial class Form1 : Form
{
private const string AppId = "APPID";
private Uri _loginUrl;
private const string _ExtendedPermissions = "user_about_me, publish_stream, offline_access";
FacebookClient fbClient = new FacebookClient();
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
string sid = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();
Login();
}
public void Login()
{
dynamic parameters = new ExpandoObject();
parameters.client_id = AppId;
parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";
parameters.response_type = "token";
parameters.display = "popup";
if (!string.IsNullOrWhiteSpace(_ExtendedPermissions))
parameters.scope = _ExtendedPermissions;
var fb = new FacebookClient();
_loginUrl = fb.GetLoginUrl(parameters);
webBrowser2.Navigate(_loginUrl.AbsoluteUri);
}
}
}