I'm using the Facebook C# SDK (http://facebooksdk.codeplex.com/releases/view/66412) and would开发者_StackOverflow like to know what the best approach would be to use it to keep my cached user data up to date?
Currently I am storing these pieces of user information:
- userid
- birthday
- name
- sex
- country
- pic
- pic_square
Has anyone given this any thought or have experience in using the SDK to keep their caches up to date? And if so, how did u architecture your solution ...
[Also, when responding please inform me of the graph api calls you made etc, fb are so obscure with this data]
Regards Rob
Here's an example implementation using 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
}
}
Use the facebook subscription feature. This way the facebook will ping your url with the changed data every time the data is changed by the user. it is a push based notification. It allows you to get real time updates for a graph object. https://developers.facebook.com/docs/reference/api/subscription/
If you are using web forms, implement FacebookSubscriptionsHttpHandler and FacebookSubscriptionVerifier.
For mvc use FacebookSubscriptionReceivedAttribute and FacebookSubscriptionVerifyAttribute
I would highly suggest you too look at the FacebookSubscriptionsHttpHandler source code http://facebooksdk.codeplex.com/SourceControl/changeset/view/08cb51f372b5#Source%2fFacebook.Web%2fFacebookSubscriptionsHttpHandler.cs
It contains xml comments on how to use it.
It is a 3 step process.
- Getting the Facebook app access token.
- Subscribing to subscriptions
- receiving and processing subscriptions
精彩评论