UWInfo Blog
發表新文章
[Join] | [忘記密碼] | [Login]
搜尋

搜尋意見
文章分類-darren
[所有文章分類]
  • ASP.NET (24)
  • ASP.NET2.0 (4)
  • ASP.NET4.0 (13)
  • JavaScript (17)
  • jQuery (5)
  • FireFox (2)
  • UW系統設定 (2)
  • SQL (7)
  • SQL 2008 (3)
  • mirror (0)
  • SVN (2)
  • IE (3)
  • IIS (6)
  • IIS6 (0)
  • 閒聊 (1)
  • W3C (4)
  • 作業系統 (3)
  • C# (14)
  • CSS (0)
  • FileServer (0)
  • HTML 5 (7)
  • CKEditor (0)
  • UW.dll (9)
  • Visual Studio (2)
  • Browser (2)
  • SEO (0)
  • Google Apps (1)
  • 網站輔助系統 (1)
  • DNS (0)
  • SMTP (3)
  • 網管 (5)
  • 社群API (3)
  • SSL (1)
  • App_Inventor (0)
  • URLRewrite (1)
  • 開發工具 (2)
  • JSON (0)
  • Excel2007 (0)
  • 試題 (0)
  • LINQ (0)
  • bootstrap (0)
  • Vue (0)
  • IIS7 (2)
  • foodpanda (0)
  • 編碼 (0)
  • 資安 (3)
  • Sourcetree (0)
  • MAUI (0)
  • CMD (0)
  • my sql (1)
所有文章分類
[darren的分類]
  • ASP.NET (48)
  • ASP.NET2.0 (15)
  • ASP.NET4.0 (34)
  • JavaScript (49)
  • jQuery (26)
  • FireFox (4)
  • UW系統設定 (3)
  • SQL (39)
  • SQL 2008 (25)
  • mirror (4)
  • SVN (4)
  • IE (9)
  • IIS (20)
  • IIS6 (1)
  • 閒聊 (7)
  • W3C (6)
  • 作業系統 (9)
  • C# (24)
  • CSS (12)
  • FileServer (1)
  • HTML 5 (11)
  • CKEditor (3)
  • UW.dll (13)
  • Visual Studio (16)
  • Browser (8)
  • SEO (1)
  • Google Apps (3)
  • 網站輔助系統 (4)
  • DNS (5)
  • SMTP (4)
  • 網管 (11)
  • 社群API (3)
  • SSL (4)
  • App_Inventor (1)
  • URLRewrite (2)
  • 開發工具 (6)
  • JSON (1)
  • Excel2007 (1)
  • 試題 (3)
  • LINQ (1)
  • bootstrap (0)
  • Vue (3)
  • IIS7 (3)
  • foodpanda (2)
  • 編碼 (2)
  • 資安 (3)
  • Sourcetree (1)
  • MAUI (1)
  • CMD (1)
  • my sql (1)
最新回應
  • IIS ARR (reverse proxy) 服務安裝
    ...more
  • UW DB 元件罕見的錯誤
    我之前好像也遇過, 考慮改一下 pg 的程式....more
  • UW DB物件 GetAllDataFromBaseTableWithCache 會嚴重影響效能
    我把它拿掉了....more
  • UW DB物件 GetAllDataFromBaseTableWithCache 會嚴重影響效能
    好, 把它拿掉.....more
  • 使用 facebook JS SDK 的心得筆記
    FB.login 沒有任何反應~ 不知道怎解決...more
  • IIS Server SSL 升級方式
    更新一版 reg 可以變 A...more
  • 防止 event 往上傳的終極方法
    eee...more
  • IIS Server SSL 升級方式
    Cool......more
  • UNT流量異常追蹤紀實
    有做 Request 的來源 IP 分析嗎 ? 說不定會有其它的發現.....more
  • facebook 網頁分享 Debug 模式
    Header 裡面的兩個 tag.. <meta property="og:i...more
標籤
  • Config ORD
  • aHR0cDovL3
  • tim
  • 20
  • 814
  • .net
  • TPBase
  • 18
  • kmfMu4Pa
  • this
  • a
  • [u2]
  • TLS 1.2
  • 58
  • 匯出
  • 8220-8205
  • web
  • 62
  • 218
  • 322
  • CS
  • 826
  • 926
  • 896
  • 280
  • [t]
  • 556
  • cros
  • 232
  • IndexOf
  • 1
  • aspnet
  • SES
  • C
  • .
  • git
  • 監控
  • asp.ne
  • GbciaVFI
  • console
  • 364
  • Data
  • AD
  • -5783
  • 250
  • -8908
  • 56
  • server
  • javascript
  • user
使用 facebook JS SDK 的心得筆記
以前只是用 facebook 的server端 API 來處理登入
這次因為活動關係而純粹使用 JS SDK 來處理 user 的發文
這裡把一些用到 function 作整理
比較特別的是 FB.login 使用時機,因為他會 window.open 新視窗
若是 ajax 資料後再呼叫,通常會被瀏覽器檔下來
使用時機最好是user點了button後就直接執行
//先檢查是不是已經登入
FB.getLoginStatus(function (response) {
    if (response.status === "connected") {
    // 已登入FB
    }
else {
        // 未登入FB
        // 盡量不要在此呼叫 FB.login , 因為彈跳視窗會被擋下來
}
});

//呼叫登入 scope:publish_stream 是要讓user同意發文到FB的權限
FB.login(function (response) {
    if (response.authResponse) {
        // 已登入,可取得 AccessToken
    } else {
        // 未登入
    }
}, { scope: 'publish_stream' });

// 檢查 user 有無同意發文到FB的權限 (publish_stream)
FB.api({ method: 'users.hasAppPermission', ext_perm: 'publish_stream' }, function (resp) {
    if (resp === "1") {
        //有同意
    } else {
        //不同意
    }
});

// 分享連結到登入者的FB牆
// msg 是發文的內容
// link, picture, caption, description 是一組的
var args = {
    message: msg,
    link: product.Link,
    picture: product.Picture,
    caption: product.Name,
    description: "超高口碑BB霜/CC霜、頂級精華液哪款半價 由你決定!"
};
FB.api('/me/feed', 'post', args, function (response) {
    if (response.id) {
        // 成功會回傳訊息id
    }
    else {
        // 分享失敗
    }
});


再補充一下,若只是單純分享網頁,可以使用 FB.ui,就不用管有無登入以及權限問題

    FB.ui({
        method: 'feed',
        name: '快去搶!超過9成的使用者滿意推薦的《玻尿酸精華》',
        link: 'http://www.shopunt.com/tch/event/2014-aqua-deluge/default.aspx',
        picture: 'http://www.shopunt.com/Upload/tch/unt/14mar/fb154x154.jpg',
        caption: 'UNT 頂級玻尿酸保濕精華液(奢華)',
        description: '熱銷破百萬 真實口碑見證的水感奇肌 逆時補水科技 快速滲透 為肌膚注入高水位……'
    },
        function (response) {
            if (response && response.post_id) {
                // handle  success
            }
            else {
                alert("facebook分享失敗!");
            }
        }
    );

darren, 2014/3/3 上午 10:06:40
文章分類:JavaScript|社群API
標籤:facebook
Bike, darren, Doug, frank, 瞇瞇, Reiko 已閱讀.
意見
阿國 say:
2017-08-23 18:43:02

FB.login 沒有任何反應~ 不知道怎解決
Vicky say:
2014-04-08 17:08:05
我比較好奇的是
之前分享 vs 後來修正 會彈出視窗分享 寫法是? 差異是?
Comment:
*Nickname:
E-mail:
Blog URL:
  • *意見內容
  • 預覽
#Nickname#
2014/3/3 上午 10:06:40
#CommentContent#
*請輸入驗證碼: 看不懂,換張圖
 
~ Uwinfo ~