因為工作需要,要寫類似心理測驗的東東
所以開始研究 facebook 的 API 但是.........網路上一堆看到的都是 C#
VB.net 的範例少的可憐,再加上這個 SDK 提供的也是 C# 飯粒
那是要我去死嗎,當然是男人就一定要先寫寫看再說
還好 C# 都看的懂只是寫不出來,因此就只好自己轉
然後要開發 facebook 的應用程式基本上可以不用這SDK
只是已經有人包裝好了不用可惜
要用的話可以到這篇來看 (c#)
http://msdn.microsoft.com/zh-tw/ee872433.aspx
http://msdn.microsoft.com/zh-tw/ee872434.aspx
http://msdn.microsoft.com/zh-tw/dd310332.aspx#Facebook
第一步當然就是下載 SDK http://facebooktoolkit.codeplex.com/
第二步加入 facebook developer,然後建立新應用程式與設定
(詳細設定過程就看上面連結的 MSDN 黃老師教學)
http://www.facebook.com/developers/
web.config
=====================================================
<appSettings>
<add key="ApiKey" value="輸入API 金鑰"/>
<add key="Secret" value="輸入應用程式密鑰"/>
<add key="Callback" value="http://localhost:4053/"/>
<add key="Suffix" value=" testapp_tw_r"/>
</appSettings>
Default.aspx
=====================================================
1.無用的 HTML tag 拿掉,ex : body,head,meta
2.隨便拉一個 Gridview到頁面上
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="FB._Default" %>
<%@ Register Assembly="Facebook.Web" Namespace="Facebook.Web.FbmlControls" TagPrefix="cc1" %>
<form id="form1" runat="server">
<div>
<asp:gridview id="GridView1" runat="server">
<Columns>
<asp:ImageField DataImageUrlField="pic_small">
</asp:ImageField>
</Columns>
</asp:gridview>
</div>
</form>
Default.aspx.vb
=====================================================
Imports Facebook
Imports Facebook.Web
Imports Facebook.Rest
Imports Facebook.Session
Imports System.Configuration
Partial Public Class _Default
Inherits CanvasIFrameBasePage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
'好孩子請到 web.config 去抓,不要寫死在這
Dim FSession As New IFrameCanvasSession("輸入API 金鑰", "輸入應用程式密鑰")
Dim List As New List(Of FacebookInfo)
Dim API As New Api(FSession)
Dim users = API.Friends.GetUserObjects
API.Status.Batch.BeginBatch()
For Each user As Facebook.Schema.user In users
Dim FacebookInfo As New FacebookInfo
FacebookInfo.uid = user.uid
FacebookInfo.pic_small = user.pic_small
FacebookInfo.name = user.name
List.Add(FacebookInfo)
Next
Me.GridView1.DataSource = List
Me.GridView1.DataBind()
End If
End Sub
Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
MyBase.RequireLogin = True
End Sub
Public Class FacebookInfo
Private m_name As String
Private m_pic_small As String
Private m_latestMessage As String
Private m_uid As Long
Public Property name() As String
Get
Return m_name
End Get
Set(ByVal value As String)
m_name = value
End Set
End Property
Public Property pic_small() As String
Get
Return m_pic_small
End Get
Set(ByVal value As String)
m_pic_small = value
End Set
End Property
Public Property latestMessage() As String
Get
Return m_latestMessage
End Get
Set(ByVal value As String)
m_latestMessage = value
End Set
End Property
Public Property uid() As Long
Get
Return m_uid
End Get
Set(ByVal value As Long)
m_uid = value
End Set
End Property
End Class
End Class
執行後會要求登入 facebook
然後簡單的好友列表就寫完了...
留言列表