问题描述
我有我的FQL查询,我有我的访问令牌。但我怎么使用C#和ASP.NET
FQL网格视图显示FQL结果:
SELECT UID,用户名,名字,姓氏,FRIEND_COUNT,pic_big
与用户
其中uid IN(SELECT UID2从相知WHERE UID1 =我( ))
这是我曾尝试:
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data这;
使用System.Drawing中;
使用System.Linq的;
使用System.Text;使用System.Threading.Tasks
;使用System.Windows.Forms的
;
使用Facebook的;
命名空间WindowsFormsApplication1
{
公共部分Form1类:表格
{
公共Form1中()
{
的InitializeComponent() ;
}
私人无效Form1_Load的(对象发件人,EventArgs五)
{
变种FB =新FacebookClient({我的访问令牌});
动态结果= fb.Get(/我);
变量名称= result.name;
MessageBox.Show(你好+名称);
}
}
}
我已经意识到,数据从Facebook的返回JSON,所以我试图反序列化
,但现在仍然运气。
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data这;
使用System.Drawing中;
使用System.Linq的;
使用System.Text;使用System.Threading.Tasks
;使用System.Windows.Forms的
;
使用Facebook的;
使用System.Dynamic;
使用Newtonsoft.Json;
命名空间WindowsFormsApplication1
{
公共部分Form1类:表格
{
公共Form1中()
{
的InitializeComponent() ;
}
私人无效Form1_Load的(对象发件人,EventArgs五)
{
}
公类MyFriends
{
公众诠释UID {搞定;设置;}
公共字符串的用户名{获得;设置;}
公共字符串FIRST_NAME {搞定;设置;}
公共字符串姓氏{搞定;设置;}
公众诠释FRIEND_COUNT {搞定;设置;}
公共字符串pic_big {搞定;设置;}
}
私人无效的button1_Click(对象发件人,EventArgs五)
{
变种FB =新FacebookClient(2A64ZAIeJVIbdZAxXRZCwYf5Bg27OgZDZD);
VAR的查询=的String.Format(SELECT UID,用户名,名字,姓氏,FRIEND_COUNT,pic_big FROM用户WHERE UID IN(SELECT UID2从相知WHERE UID1 =我()));
动态参数=新ExpandoObject();
parameters.q =查询;
动态结果= fb.Get(/ FQL,参数);
=结果与JsonConvert.DeserializeObject LT; MyFriends>(结果);
//MessageBox.Show(\"Hi+结果);
}
}
}
C#的WinForms
使用 DataGridView的
控制就像你在标题中指定的解决方案。
1)的修改你的 MyFriend
类后,我改变了它一点点
公共类MyFriends
{
众长UID {搞定;组; }
公共字符串的用户名{获得;组; }
公共字符串FIRST_NAME {搞定;组; }
公共字符串姓氏{搞定;组; }
众长? FRIEND_COUNT {搞定;组; } //可空
公共字符串pic_big {搞定;组; }
}
2)DataGridView控件添加到您的窗体
3)反序列化您 result.data code>使用
JsonConvert
到列表中。你也应该通过 result.data.ToString()
或它会给一个例外。
4)绑定您的新名单 DataGridView.Datasource
变种FB =新FacebookClient(的accessToken);
VAR的查询=的String.Format(@SELECT UID,用户名,名字,姓氏,FRIEND_COUNT,pic_big
从用户其中uid IN(SELECT UID2从相知WHERE UID1 =我()) );
动态参数=新ExpandoObject();
parameters.q =查询;
动态结果= fb.Get(/ FQL,参数);
名单,LT; MyFriends> Q = JsonConvert.DeserializeObject<名单,LT; MyFriends>>(results.data.ToString());
dataGridView1.DataSource = Q;
结果:
I have my FQL query and i have my access token. But how do i display FQL results in GRID VIEW using C# and ASP.NET?
FQL:
SELECT uid, username, first_name, last_name, friend_count, pic_big
FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
This is what i have tried:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Facebook;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var fb = new FacebookClient("{My Access Token}");
dynamic result = fb.Get("/me");
var name = result.name;
MessageBox.Show("Hi " + name);
}
}
}
I have realized that the data is returned from Facebook as JSON so i attempt to deserialize
but still now luck.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Facebook;
using System.Dynamic;
using Newtonsoft.Json;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public class MyFriends
{
public int uid {get; set;}
public string username {get; set;}
public string first_name {get; set;}
public string last_name {get; set;}
public int friend_count {get; set;}
public string pic_big {get; set;}
}
private void button1_Click(object sender, EventArgs e)
{
var fb = new FacebookClient("2A64ZAIeJVIbdZAxXRZCwYf5Bg27OgZDZD");
var query = string.Format("SELECT uid, username, first_name, last_name, friend_count, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");
dynamic parameters = new ExpandoObject();
parameters.q = query;
dynamic results = fb.Get("/fql", parameters);
results = JsonConvert.DeserializeObject<MyFriends>(results);
//MessageBox.Show("Hi " + results);
}
}
}
C# Winforms
solution using a DataGridView
control like you specify in the title.
1) Modify your MyFriend
class, I changed it a little bit
public class MyFriends
{
public long uid { get; set; }
public string username { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public long? friend_count { get; set; } //nullable
public string pic_big { get; set; }
}
2) Add DataGridView control to your form
3) Deserialize your result.data
using JsonConvert
to a List. You should also pass result.data.ToString()
or it will give an exception.
4) Bind your new list to DataGridView.Datasource
var fb = new FacebookClient("accessToken");
var query = string.Format(@"SELECT uid, username, first_name, last_name, friend_count, pic_big
FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");
dynamic parameters = new ExpandoObject();
parameters.q = query;
dynamic results = fb.Get("/fql", parameters);
List<MyFriends> q = JsonConvert.DeserializeObject<List<MyFriends>>(results.data.ToString());
dataGridView1.DataSource = q;
Result:
这篇关于使用C#显示FQL结果DataGridView中(的WinForms)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!