本文整理汇总了C#中Facebook.FacebookClient.Get方法的典型用法代码示例。如果您正苦于以下问题:C# FacebookClient.Get方法的具体用法?C# FacebookClient.Get怎么用?C# FacebookClient.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook.FacebookClient
的用法示例。
在下文中一共展示了FacebookClient.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FacebookLayer
/*
public FacebookLayer()
{
authorizer = new CanvasAuthorizer { Perms = "publish_stream" };
if (authorizer.Authorize())
{
fbClient = new FacebookClient(CurrentSession.AccessToken);
User = new FacebookUser();
try
{
var me = (IDictionary<string, object>) fbClient.Get("me");
User.FacebookId = (string) me["id"];
User.FacebookName = (string) me["first_name"];
}
catch
{
isAccessTokenValid = false;
return;
}
isAccessTokenValid = true;
IDictionary<string, object> friendsData = (IDictionary<string, object>) fbClient.Get("me/friends");
facebookData = new FacebookData(User, friendsData);
SortedFriends = facebookData.SortedFriends;
}
}
*/
public FacebookLayer(CanvasAuthorizer auth)
{
this.authorizer = auth;
if (this.authorizer.Authorize())
{
fbClient = new FacebookClient(CurrentSession.AccessToken);
User = new FacebookUser();
try
{
var me = (IDictionary<string, object>) fbClient.Get("me");
User.FacebookId = (string) me["id"];
User.FacebookName = (string) me["first_name"];
}
catch
{
isAccessTokenValid = false;
return;
}
isAccessTokenValid = true;
IDictionary<string, object> friendsData = (IDictionary<string, object>) fbClient.Get("me/friends");
facebookData = new FacebookData(User, (IList<object>)friendsData["data"]);
}
}
示例2: getFeed
// public IEnumerable<string> getFeed()
public object getFeed()
{
try
{
var fb = new FacebookClient(AccessToken) { AppId = AppId, AppSecret = AppSecrete };
List<object> _lisObj = new List<object>();
List<object> _lisObj2 = new List<object>();
dynamic results = fb.Get("/55269232341_10154511844402342/comments");
var a = results[1].next;
dynamic results2 = fb.Get(a);
var b = results[1].next;
foreach (object result in results2.data)
{
_lisObj2.Add(result);
}
var c = results2[1].next;
foreach (object result in results.data)
{
_lisObj.Add(result);
}
return _lisObj;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadKey();
return null;
}
}
示例3: About
public ActionResult About()
{
ViewBag.Friends = new List<FbUser>();
ViewBag.FriendsCount =0;
ViewBag.Message = "Your application description page.";
var claimsIdentity = HttpContext.User.Identity as ClaimsIdentity;
//var access_token = claimsIdentity.FindAll("name").First().ToString();
//var access_token = claimsIdentity.FindAll("BLEE");
//var access_token2 = access_token.First();
//var access_token3 = access_token2.ToString();
var claimlist = from claims in HttpContext.GetOwinContext().Authentication.User.Claims
select new ExtPropertyViewModel
{
Issuer = claims.Issuer,
Type = claims.Type,
Value = claims.Value
};
try
{
var access_token = HttpContext.GetOwinContext().Authentication.User.Claims.Where(c => c.Type == "FacebookAccessToken").First().Value;
ViewBag.Token = access_token;
var fb = new FacebookClient(access_token);
//var friendListData = fb.Get("/me/friends");
//JObject friendListJson = JObject.Parse(friendListData.ToString());
//List<FbUser> fbUsers = new List<FbUser>();
//foreach (var friend in friendListJson["data"].Children())
//{
// FbUser fbUser = new FbUser();
// fbUser.Id = friend["id"].ToString().Replace("\"", "");
// fbUser.Name = friend["name"].ToString().Replace("\"", "");
// fbUsers.Add(fbUser);
//}
//ViewBag.Friends = fbUsers;
//ViewBag.FriendsCount = fbUsers.Count;
string ans = fb.Get("me").ToString();
ViewBag.Me = ans;
string ans2 = fb.Get("me/permissions").ToString();
ViewBag.Permissions = ans2;
string ans4 = fb.Get("me/friends", new { fields = new[] { "name, id" } }).ToString();
ViewBag.Friends = ans4;
return View(claimlist.ToList<ExtPropertyViewModel>());
}
catch
{
return View(new List<ExtPropertyViewModel>());
}
}
示例4: FbAuth
public ActionResult FbAuth(string returnUrl)
{
var client = new FacebookClient();
var oauthResult = client.ParseOAuthCallbackUrl(Request.Url);
// Build the Return URI form the Request Url
var redirectUri = new UriBuilder(Request.Url);
redirectUri.Path = Url.Action("FbAuth", "Account");
dynamic result = client.Get("/oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["FacebookAppId"],
redirect_uri = redirectUri.Uri.AbsoluteUri,
client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
code = oauthResult.Code,
});
// Read the auth values
string accessToken = result.access_token;
DateTime expires = DateTime.UtcNow.AddSeconds(Convert.ToDouble(result.expires));
dynamic me = client.Get("/me", new { fields = "first_name,last_name,email", access_token = accessToken });
// Read the Facebook user values
long facebookId = Convert.ToInt64(me.id);
string firstName = me.first_name;
string lastName = me.last_name;
string email = me.email;
// Add the user to our persistent store
var userService = new UserService();
userService.AddOrUpdateUser(new User
{
Id = facebookId,
FirstName = firstName,
LastName = lastName,
Email = email,
AccessToken = accessToken,
Expires = expires
});
// Set the Auth Cookie
FormsAuthentication.SetAuthCookie(email, false);
// Redirect to the return url if availible
if (String.IsNullOrEmpty(returnUrl))
{
return Redirect("/App");
}
else
{
return Redirect(returnUrl);
}
}
示例5: Callback
public ActionResult Callback(string code, string state)
{
FacebookOAuthResult oauthResult;
if (FacebookOAuthResult.TryParse(Request.Url, out oauthResult))
{
if (oauthResult.IsSuccess)
{
var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
oAuthClient.RedirectUri = new Uri(redirectUrl);
dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken(code);
string accessToken = tokenResult.access_token;
DateTime expiresOn = DateTime.MaxValue;
FacebookClient fbClient = new FacebookClient(accessToken);
dynamic me = fbClient.Get("me?fields=id,name");
long facebookId = Convert.ToInt64(me.id);
var account = Accounts.Get().Where(Accounts.Columns.ForeignID, Actions.Equal, facebookId).SelectOne();
if (account == null)
{
account = new Account { FBKey = accessToken, Name = me.name, ForeignID = facebookId.ToString() };
account.Insert();
}
else
{
account.FBKey = accessToken;
account.Name = me.name;
account.Update();
}
dynamic pages = fbClient.Get("me/accounts");
foreach (var p in pages.data)
{
FBPage page = FBPages.Get().Where(FBPages.Columns.ForeignID, Actions.Equal, p.id).SelectOne();
if (page == null)
{
page = new FBPage { ForeignID = p.id, Name = p.name, Token = p.access_token };
page.Insert();
}
else
{
page.Name = p.name;
page.Token = p.access_token;
page.Update();
}
}
ViewBag.Name = account.Name;
}
}
return View();
}
示例6: loadFacebookData
protected void loadFacebookData()
{
try
{
var client = new FacebookClient(new InfoModule().readFacebookAccessToken(Request["id"]));
dynamic response = client.Get("me");
dynamic response2 = client.Get("me?fields=picture");
dynamic response3 = client.Get("me?fields=books");
dynamic response4 = client.Get("me?fields=friends,events,sports,statuses.limit(3)");
Picture.ImageUrl = response2.picture.data.url;
HyperLink.NavigateUrl = response.link;
HyperLink.Text = response.link;
NameLabel.Text = response.name;
BirthdayLabel.Text = response.birthday;
GenderLabel.Text = response.gender;
HometownLabel.Text = response.hometown.name;
BioLabel.Text = response.bio;
EmailLabel.Text = response.email;
ReligionLabel.Text = response.religion;
WorkLabel.Text = "";
EducationLabel.Text = "";
BooksLabel.Text = "";
EventsLabel.Text = "";
StatusLabel.Text = "";
FriendsLabel.Text = response4.friends.summary.total_count.ToString();
foreach (dynamic workplace in response.work)
{
WorkLabel.Text += workplace.employer.name + "<br />";
}
foreach (dynamic school in response.education)
{
EducationLabel.Text += school.school.name + "<br />";
}
foreach (dynamic book in response3.books.data)
{
BooksLabel.Text += book.name + "<br />";
}
foreach (dynamic events in response4.events.data)
{
EventsLabel.Text += events.name + "<br />";
}
foreach (dynamic status in response4.statuses.data)
{
StatusLabel.Text += status.message + "<br /><br />";
}
}
catch (NullReferenceException e)
{
}
}
示例7: Main
static void Main(string[] args)
{
JArray ja;
Console.WriteLine("Starting....");
string access_token = "Token";
FacebookClient fbclient = new FacebookClient(access_token);
dynamic Albumlist = fbclient.Get("/me/albums");
int count = (int)Albumlist.data.Count;
for (int i = 0; i < count; i++)
{
Console.WriteLine(i + " " + Albumlist.data[i].id + " " + Albumlist.data[i].name);
}
Console.WriteLine("");
Console.WriteLine("Enter the Number of the Album to download");
string input = Console.ReadLine();
int number;
Int32.TryParse(input, out number);
String strrr = "/" + Albumlist.data[number].id + "/photos";
dynamic pics = fbclient.Get(strrr);
count = (int)pics.data.Count;
String ssss = Convert.ToString(pics.data);
//JObject ob = JObject.Parse(ssss);
ja = JArray.Parse(ssss);
WebClient wc = new WebClient();
int j = 0;
try
{
string folderpath = String.Format(@"{0}\Album", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
while (ja[j]["images"][0]["source"].ToString() != null)
{
wc.DownloadFile(ja[j]["images"][0]["source"].ToString(), folderpath + "\\" + j.ToString() + ".jpg");
Console.WriteLine("Downloading : " + folderpath + "\\" + j.ToString() + ".jpg");
j++;
}
Console.WriteLine("Download Complete");
}
catch (Exception esss)
{
}
Console.WriteLine("Download Complete");
Console.ReadKey();
}
示例8: DoFacebook
public static void DoFacebook()
{
FacebookClient facebookClient = new FacebookClient();
dynamic result = facebookClient.Get("oauth/access_token", new
{
client_id = "537452296325126",
client_secret = "aa2ce963862cc139e64c1339f28bdfdd",
grant_type = "client_credentials"
});
dynamic me = facebookClient.Get("me");
var id = me.id;
var name = me.name;
}
示例9: GetFriends
public static Dictionary<string, string> GetFriends(string access_token)
{
FacebookClient client = new FacebookClient(access_token);
dynamic list = client.Get("me/friends");
int noOfFriends = (int)list.data.Count;
Dictionary<string, string> id = new Dictionary<string, string>();
for (int i = 0; i < noOfFriends; i++)
{
id.Add(list.data[i].id, list.data[i].name);
}
list = client.Get("me");
id.Add(list.id, list.name);
return id;
}
示例10: FacebookHandshake
public static FacebookUserModel FacebookHandshake(string redirectUri, HttpRequestBase request)
{
var model = new FacebookUserModel();
var client = new FacebookClient();
var oauthResult = client.ParseOAuthCallbackUrl(request.Url);
// Build the Return URI form the Request Url
// Exchange the code for an access token
dynamic result = client.Get("/oauth/access_token", new
{
client_id = SocialMediaConnectConstants.AppId,
redirect_uri = redirectUri,
client_secret = SocialMediaConnectConstants.AppSecret,
code = oauthResult.Code
,
});
// Read the auth values
string accessToken = result.access_token;
//If needed you can add the access token to a cookie for pulling additional inforamtion out of Facebook
//DateTime expires = DateTime.UtcNow.AddSeconds(Convert.ToDouble(result.expires));
//HttpCookie myCookie = HttpContext.Current.Request.Cookies["accessToken"] ?? new HttpCookie("accessToken");
//myCookie.Values["value"] = accessToken;
//myCookie.Expires = expires;
//HttpContext.Current.Response.Cookies.Add(myCookie);
// Get the user's profile information
dynamic me = client.Get("/me",
new
{
fields = "name,picture,first_name,last_name,email,id,birthday,location,gender",
access_token = accessToken
});
// Read the Facebook user values
model.UserId = me.id;
model.FirstName = me.first_name;
model.LastName = me.last_name;
model.Email = me.email;
model.ProfileImageUrl = ExtractImageUrl(me);
model.Birthday = me.birthday;
model.Gender = me.gender;
model.Location = me.location["name"].ToString();
return model;
}
示例11: button1_Click
private void button1_Click(object sender, EventArgs e)
{
// Specify a name for main folder.
string folderName = @"c:\Facebook Albums";
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
MessageBox.Show("please give Token " );
return;
}
var FBtoken = textBox1.Text;
var fb = new FacebookClient(FBtoken);
dynamic Albums = fb.Get("me/albums?fields=name");
foreach (dynamic albumInfo in Albums.data)
{
var AlbumName = albumInfo.name;
var AlbumId = albumInfo.id;
//MessageBox.Show(" Dowloading album =" +AlbumName );
string pathString = System.IO.Path.Combine( folderName, AlbumName);
//creating subfolders in albums name
System.IO.Directory.CreateDirectory(pathString);
dynamic Photos = fb.Get(AlbumId+"/photos?fields=name,images");
int n = 0; // for Image name .Because facebook has more version of one image with same id and name
foreach (dynamic PhotosInfo in Photos.data)
{
foreach (dynamic Image in PhotosInfo.images)
{
var PhotoName =n.ToString() + ".png";
string ImagePathString = System.IO.Path.Combine(pathString, PhotoName);
string ImagesSource = Image.source;
ImageDownload(ImagesSource, ImagePathString);
n++;
}
}
}
}
示例12: FacebookCallback
public ActionResult FacebookCallback(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = "1539813469663309",
client_secret = "0883fd6699f9f387a575e12d28391751",
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});
var accessToken = result.access_token;
// Store the access token in the session
Session["AccessToken"] = accessToken;
// update the facebook client with the access token so
// we can make requests on behalf of the user
fb.AccessToken = accessToken;
// Get the user's information
dynamic me = fb.Get("me?fields=first_name,last_name,id,email, friends, likes");
Console.WriteLine(me);
// Set the auth cookie
FormsAuthentication.SetAuthCookie(me.email, false);
return RedirectToAction("Index", "Home");
}
示例13: Page_Load
//HTTPMODULE!!
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (User.IsInRole("Triphulcas"))
WelcomeMessage = Resources.Resource1.SnippetTriphulcasWelcomeMessage;
if (!String.IsNullOrEmpty(User.AccessToken))
{
try
{
var client = new FacebookClient(User.AccessToken);
dynamic result = client.Get("me", new { fields = "id" });
pImage.Src = String.Format(Resources.Resource1.FacebookPictureUrl, result.id);
pWelcome.InnerText = WelcomeMessage;
pLogout.Attributes.Remove("hidden");
pLogout.Attributes["style"] = "display:block";
}
catch (FacebookOAuthException)
{
}
}
}
else
{
//ugly, I know.
pWelcome.InnerHtml = String.Format("{0} <a class=\"popup\" href=\"/authentication.aspx\">{1}</a>.",
Resources.Resource1.SnippetShowFaceBeforeLink,
Resources.Resource1.SnippetShowFaceLink);
}
}
示例14: Agregar
public ActionResult Agregar()
{
bool permiteAcceso = false;
Boolean debug = Boolean.Parse(ConfigurationManager.AppSettings["debug"]);
permiteAcceso = debug;
if (Session["AccessToken"] != null)
{
var accessToken = Session["AccessToken"].ToString();
var client = new FacebookClient(accessToken);
dynamic result = client.Get("me", new { fields = "id" });
if (result.id == "100002979715059")
{
permiteAcceso = true;
}
}
if (permiteAcceso)
{
var servAlojamientos = new AlojamientoService();
var ListTipos = new List<ParDeValores>();
//ListTipos.Add(new ParDeValores() { id = -1, descripcion = "Seleccione uno" });
ListTipos.AddRange(servAlojamientos.GetTiposAlojamiento().Select(x => new ParDeValores() { id = x.ID, descripcion = x.Descripcion }));
ViewBag.ListTipos = ListTipos;
return View();
}
return new EmptyResult();
}
示例15: GetStreamItemCollection
public StreamItemCollection GetStreamItemCollection()
{
try
{
ExtendAccesstoken();
string accesstoken = "";
string appid = "";
string appsecret = "";
FacebookClient client = new FacebookClient();
dynamic Me = client.Get(@"me/home");
string aboutMe = Me.about;
}
catch (Exception exc)
{
throw;
}
return null;
}