• 在网页中获取 facebook page 的内容


    参考 : http://www.ibm.com/developerworks/cn/opensource/os-cn-facebookapi/

    1.首先你要有 facebook page, 内容要公开, 登入admin-> setting -> general -> page visibility = Page Published

    2.你要有个 facebook app , 需要 App ID 和 App Secret .

    3.然后你需要一个 access_token 

    GET https://graph.facebook.com/oauth/access_token?client_id={App ID}&client_secret={App Secret}&grant_type=client_credentials" 

    用这个 url 就可以获取了.

    然后你就可以访问页面内容了 

    GET https://graph.facebook.com/{Page_ID or Page_Name}/feed?access_token={3.access_token}"

    返回的是json, 之后你就可以自己看看了。

    c# 

    protected void Page_Load(object sender, EventArgs e)
    {
        RegisterAsyncTask(new PageAsyncTask(async (t) =>
        {
            using (var client = new HttpClient())
            {
                string APP_ID = "xx";
                string APP_SECRET = "xx";
                client.BaseAddress = new Uri("https://graph.facebook.com");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                 
                HttpResponseMessage response = await client.GetAsync("oauth/access_token?client_id=" + APP_ID + "&client_secret=" + APP_SECRET + "&grant_type=client_credentials");
                if (response.IsSuccessStatusCode)
                {
                    string text = await response.Content.ReadAsStringAsync(); //return text
                    int ipos = text.IndexOf("=");
                    string accessToken = text.Substring(ipos + 1);
    
                    response = await client.GetAsync("OnlineStoreStooges/feed?access_token=" + accessToken);
                    if (response.IsSuccessStatusCode)
                    {
                        string json = await response.Content.ReadAsStringAsync(); //return json
                    }
                }
            }
        }));
    }

    js with angularjs :

    var app = angular.module("app", []);
    app.controller("ctrl", ["$scope", "$http", function ($scope, $http) {
        var APP_ID = "xx";
        var APP_SECRET = "xx";
        $http({
            method: "get",
            url: "https://graph.facebook.com/oauth/access_token?client_id=" + APP_ID + "&client_secret=" + APP_SECRET + "&grant_type=client_credentials"
        }).success(function (data) {
            var ipos = data.indexOf("=");
            var accessToken = data.substring(ipos + 1);
            $http({
                method: "get",
                url: "https://graph.facebook.com/OnlineStoreStooges/feed?access_token=" + accessToken
            }).success(function (data) {
                log(data);  
            });
        });
    }]);
  • 相关阅读:
    AxInterop.VPIClient DLL注册
    多个事务同时操作数据库
    aspx小试
    WPF 或得PNG图片的外形Path的Data
    Spass导出数据
    Excel VBA小试
    合并Excel文件
    asp.net 中文编码问题
    Delphi中的容器类(3)
    Delphi中的容器类(1)
  • 原文地址:https://www.cnblogs.com/keatkeat/p/4413028.html
Copyright © 2020-2023  润新知