下面是一個使用MVC3的範例:
public class SubscriptionController : Controller
{
private const string SubscriptionVerificationToken = "E5FB84E0-F425-445A-86C8-9FC598E79B1E";
private const string CallbackUrl = "http://mysite.com/subscription/verify";
public void Index()
{
FacebookClient fb = new FacebookClient(FacebookApplication.Current);
dynamic result = fb.Post(
string.Format("/{0}/subscriptions", FacebookApplication.Current.AppId), new Dictionary<string, object>
{
{ "object","user"},
{ "fields","friends" },
{"callback_url", CallbackUrl },
{ "verify_token", SubscriptionVerificationToken }
});
}
[HttpGet]
[FacebookSubscriptionVerify(SubscriptionVerificationToken)]
public void Verify(FacebookClient fb)
{
FacebookSubscriptionVerifiedResult verifiedResult = new FacebookSubscriptionVerifiedResult();
verifiedResult.ExecuteResult(ControllerContext);
}
[HttpPost]
[FacebookSubscriptionReceived]
[ActionName("Verify")]
public void Receive()
{
//handle response
}
}
嗨Prabir,你能給我如何使用FacebookSubscriptionReceivedAttribute和FacebookSubscriptionVerifyAttribute以一個簡單的例子訂閱用戶姓名,出生日期和國家?我正在使用MVC謝謝! – 2011-08-15 08:31:58