FriendList + User Status C# does not work

Oct 19, 2010 at 9:15 AM
Edited Oct 19, 2010 at 9:18 AM

Hi there,

im trying to build a application in C# that shows me my facebook friend list with the Facebook Development Kit.
This works propably and is not my Problem i have.
I would like a popup that shows me the last Status Message of my friend if i click on the Name of my friend.
This does not work i tryed the whole day put the status.get methode won't work.

Can anybody help me?

I have a FriendList and a DataGrid to show my friends.
Additionally i have 2 Textboxes one that should display my current status
and the secent to update my status.

This does not work, too.
I can't even read my own Status Message what am i doing wrong?

Here is my Source code:

 

[quote]

using System;
using System.Windows.Forms;
using DesktopApp.Properties;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Facebook.Schema;
using Facebook.Web;
using Facebook.Winforms;

namespace DesktopApp
{
    public partial class DesktopApp : Form
    {
        private bool _isLoading;
        public DesktopApp()
        {
            InitializeComponent();
            //Disable selection notifications
            _isLoading = true;

            //Connect to Facebook using Facebook Deleoper Toolkit
            facebookService1.ApplicationKey = Settings.Default.APIKey;
            //facebookService1.Secret = Settings.Default.APISecret;        <-- Secret was not found
            facebookService1.ConnectToFacebook();
        }

        private void DesktopApp_Load(object sender, EventArgs e)
        {
            #region FDT Control Example

            //Set up Facebook Development Toolkit controls
            SetupFDTControls();

            //Bind friends list control to current users's friends
            friendList1.Friends = facebookService1.Friends.GetUserObjects();

            #endregion FDT Control Example

            #region Winform control Example

            //Set up standard .Net Winform controls
            SetupWinformControls();

            //Bind DataGridView to current users's friends
            dataGridView1.DataSource = facebookService1.Friends.GetUserObjects();

            #endregion Winform control Example


            //Enable selection notification
            _isLoading = false;
        }

        private void SetupFDTControls()
        {
            //Wire up event handlers
            friendList1.FriendSelected += friendList1_FriendSelected;
        }

        private void SetupWinformControls()
        {
           //Wire up event handlers
            dataGridView1.SelectionChanged += dataGridView1_SelectionChanged;

           
            //Turn off colum generation
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
           
            //Define first name column
            DataGridViewTextBoxColumn firstNameColumn = new DataGridViewTextBoxColumn
            {
                DataPropertyName = "first_name",
                HeaderText = "First Name",
                ValueType = typeof(string)
            };
                   
            //Define last name column
            DataGridViewTextBoxColumn lastNameColumn = new DataGridViewTextBoxColumn
            {
                DataPropertyName = "last_name",
                HeaderText = "Last Name",
                ValueType = typeof(string)
            };

            //Add Columns to data grid
            dataGridView1.Columns.Add(firstNameColumn);
            dataGridView1.Columns.Add(lastNameColumn);
        }

        private void friendList1_FriendSelected(object sender, Facebook.Winforms.FriendSelectedEventArgs e)
        {
            //Get selected user object and pass to display
            DisplayUserDetail(e.User);
        }


        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            //Get Selected user object and pass to display
            if (dataGridView1.SelectedRows.Count <= 0) return;
            user selectedUser = dataGridView1.SelectedRows[0].DataBoundItem as user;
            DisplayUserDetail(selectedUser);
        }

        private void DisplayUserDetail(user selectedUser)
        {
            //Ignore during initial load
            if (_isLoading) return;

            //Load User Specific details
            MessageBox.Show("User ID:", string.Format("{0}",selectedUser.uid, selectedUser.status));
                     
             Facebook.Schema.user user = facebookService1.Users.GetInfo(selectedUser.uid);
            //MessageBox.Show(string.Format("{0}",user));
            long? userid = selectedUser.uid;
            long StatusUID = unchecked((long)userid);
            Facebook.Schema.user_status message = user.status;
            MessageBox.Show("User ID : " + (string.Format("{0}", selectedUser.uid)) + "Message: " + message );               

     
        }

        private void btnStatus_Click(object sender, EventArgs e)
        {
            try
            {
                //Update Facebook Status and refresh form's status display
                facebookService1.Status.Set(txtNewStatus.Text.Trim());
                GetCurrentStatus();
                txtNewStatus.Text = string.Empty;
            }
            catch (Exception ex)
            {
                txtCurrentStatus.Text = ex.Message;
            }
        }

        private void GetCurrentStatus()
        {
            //Recieve and display the current user's Status
            txtCurrentStatus.Text = facebookService1.Status.Get()[0].message;
        }

        private void txtCurrentStatus_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void btnExtPerm_Click(object sender, EventArgs e)
        {
            /*

            Promt user for extended permission to update Facebook Status
             string extendedPermUrl=
                 string.Format("http://www.facebook.com/authorize.php?api_key=(API_Key)&y=1.0&text_perm=status_update");
             Opem with browser
             System.Diagnostics.Process.Start(extendedPermUrl);

            HttpStyleUriParser
             HttpStyleUriParser:https://graph.facebook.com/oauth/authorize?client_id=(xxxKEYxxx)&
            redirect_url=http://www.facebook.com/connect/login_success.html&
            type=user_agent&
           display=popup
 
        }
    }
}

[/quote]