c# - Like gate mechanism with Asp.Net MVC Facebook -
i'm trying out asp.net mvc 4 facebook template , "framework" , i'm finding hard on internet, except "birthday app" sample.
i'm building simple facebook application "like gate", meaning people should able access app if have "liked" page.
my idea check in controller wether user has "liked" fan page , if has not, redirect him "likefirst" view.
here's controller, straight template:
[facebookauthorize("email", "user_photos")] public async task<actionresult> index(facebookcontext context) { if (modelstate.isvalid) { var user = await context.client.getcurrentuserasync<myappuser>(); if(//how check user has liked fan page) { return view(user); } else { return view("likefirst"); } } return view("error"); } from got in sample, framework uses "myappuser" object construct facebook query.
this type used in sample app.
public class myappuser { public string id { get; set; } public string name { get; set; } public string email { get; set; } [jsonproperty("picture")] // renames property picture. [facebookfieldmodifier("type(large)")] // sets picture size large. public facebookconnection<facebookpicture> profilepicture { get; set; } [facebookfieldmodifier("limit(8)")] // sets size of friend list 8, remove friends. public facebookgroupconnection<myappuserfriendsimple> friends { get; set; } [facebookfieldmodifier("limit(16)")] // sets size of photo list 16, remove photos. public facebookgroupconnection<facebookphoto> photos { get; set; } } from facebook documentation, should able check through doing http /profile_id/likes/page_id, how should using asp.net mvc facebook framework? there can change in myappuser class? different?
thanks!
so had challenge morning - had tinker bit figure out. here's
create "likes" property on user type
public class myappuser { public string id { get; set; } public string name { get; set; } public string email { get; set; } public facebookgroupconnection<facebooklike> likes { get; set; } ... } of course means have create facebooklike type
public class facebooklike { public string id { get; set; } public string name { get; set; } } add following permission string facebookauthorizeattribute
[facebookauthorize("email", "user_photos", "user_likes")] public async task<actionresult> index(facebookcontext context) { ... } and find out of user likes page, find page id , put following code in relevant controller method in want perform check -
if (user.likes.data.firstordefault(like => like.id == "<your_fb_pageid>") == null) { return view("likeus"); } hope helps
Comments
Post a Comment