Skip to content

Instantly share code, notes, and snippets.

@anuith
Created June 24, 2012 19:56
Show Gist options
  • Save anuith/2984675 to your computer and use it in GitHub Desktop.
Save anuith/2984675 to your computer and use it in GitHub Desktop.
Windows Phone Hackathon : Facebook & Instagram Sample - Facebook Page Code - Get Page Info
private void ButtonGo_Click(object sender, RoutedEventArgs e) {
string facebookname = TextBox_FBName.Text;
// Reset textblocks, image, and listbox
Image_Cover.Source = null;
TextBlock_Desc.Text = "";
TextBlock_Name.Text = "";
ListBox_Photos.Items.Clear();
// Initializes new Facebook Client
FacebookClient client = new FacebookClient(accessToken);
client.GetCompleted += new
EventHandler<FacebookApiEventArgs>(client_GetCompleted);
// Get profile info
client.GetAsync(facebookname, null, "profile");
// Get profile picture
Image_Profile.Source = new BitmapImage(
new Uri("https://graph.facebook.com/" + facebookname + "/picture"));
}
private void client_GetCompleted(object sender, FacebookApiEventArgs e) {
JObject json = JObject.Parse(e.GetResultData().ToString());
string userstate = (string)e.UserState;
if ("profile" == userstate)
{
Deployment.Current.Dispatcher.BeginInvoke(() => SetPageInfo(json));
}
}
private void SetPageInfo(JObject jsonData) {
// Get data from json path /name
TextBlock_Name.Text = jsonData["name"].ToString();
if (null != jsonData["description"])
{
// Get data from json path /description
TextBlock_Desc.Text = jsonData["description"].ToString();
}
if (null != jsonData["cover"])
{
// Get data from json path /cover/source
string coverJson = jsonData["cover"].ToString();
JObject coverData = JsonConvert.DeserializeObject<JObject>(coverJson);
Image_Cover.Source = new BitmapImage(new Uri(coverData["source"].ToString()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment