通过 OpenGraph 发布到 Facebook 页面

发布于 2024-10-07 03:44:29 字数 253 浏览 2 评论 0原文

通过所有文章和指南,我似乎无法弄清楚如何通过 Facebook 进行身份验证,以便我可以从我们的网站发布到我们的 Facebook 页面。您能给我一些“如何为傻瓜做到这一点”吗?最主要的是我不知道如何获取该 acces_token 。问题是:

  1. 我是否需要首先创建某种 facebook 应用程序
  2. 应用程序是否会像页面管理员一样发布到页面墙上,或者作为应用程序,换句话说 - 作为页面管理员如何做到这一点?

through all the articles and guides, I can't seem to figure out how to authenticate with Facebook so that I could post from our website to our Facebook page. Can you please give me some sort of "how to do exactly this for dummies"? The main thing is that I can't figure out how to get that acces_token. The questions are:

  1. do I need to create some sort of facebook application first?
  2. will the app post to the page's wall as a page admin would, or as an application, in other words - how to do it as a page admin?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡墨 2024-10-14 03:44:29

是的,您必须创建一个 Facebook 应用程序才能让您网站的用户在 Facebook 上发布他们的内容。

使用 OAuth 2.0 的身份验证过程非常简单:

  • 调用 https://graph.facebook.com/oauth/authorizeclient_id=<您的应用的 client_id>&redirect_uri=<您的重定向 URU> 。正如您所看到的,您必须传输您的 client_id 和 Facebook 在流程结束时重定向的 URI。您还可以传输数据参数,该数据参数在整个过程中保持不变。对于跟踪用户很有用。
  • 调用 https://graph.facebook.com/oauth/access_token?client_id=<您应用的 client_id>&redirect_uri=h<您的重定向 URU>&client_secret=<您应用的 client_secret>&code= code 参数由上一步调用中的重定向 URI 给出
  • ​​https://graph.facebook.com/me?access_token= ,使用先前重定向返回的临时 access_token,然后您将获得真正的 access_token

更多信息请参见:

http://developers.facebook.com/docs/authentication/

Yes, you have to create a Facebook application in order to let the users of your website post their stuff on Facebook.

The authenticate process, using OAuth 2.0, is quite simple:

  • call https://graph.facebook.com/oauth/authorizeclient_id=<your app's client_id>&redirect_uri=<your redirect URU>. As you can see, you have to transmit your client_id and an URI where Facebook will redirect at the end of the process. You can also transmit a data parameter, which will go unchanged through the process. Useful to keep track of the user.
  • call https://graph.facebook.com/oauth/access_token?client_id=<your app's client_id>&redirect_uri=h<your redirect URU>&client_secret=<your app's client_secret>&code=<code> The code parameter is given by the call to the redirect URI on the previous step
  • call https://graph.facebook.com/me?access_token=<access_token>, using the ad-hoc access_token returned by the previous redirect, and then you get the real access_token.

More infos here:

http://developers.facebook.com/docs/authentication/

迟月 2024-10-14 03:44:29

您需要找到您的用户 ID 和访问令牌
opengraph explorer

以下 Java 代码(使用 apache http 客户端),在指定用户 ID 的 facebook 墙上发布消息。

public class Main2 {

    public static void main(String[] args) {



        HttpClient httpclient = new DefaultHttpClient();

        try {


            String accessToken = "AAACEdEose0cBANzDaBq";

            String message = "Hey Jude, don't make it bad";

            String userId = "200501511023";

            String requestURL = "https://graph.facebook.com/"+userId+"/feed";

            HttpPost httpPost = new HttpPost( requestURL );

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("access_token", accessToken));
            nameValuePairs.add(new BasicNameValuePair("message", message));


            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));


            // Create a response handler
            ResponseHandler<String> rh = new ResponseHandler<String>() {

                public String handleResponse(HttpResponse hr) throws ClientProtocolException, IOException {
                    return "\n" + hr.getStatusLine() + "\n\n"
                        + dumpStream(hr.getEntity().getContent());
                }
            };

            System.out.println("****************************************");
            System.out.println("executing request " + httpPost.getURI());
            System.out.println("****************************************");

            String response = httpclient.execute(httpPost, rh);


            System.out.println("----------------------------------------");
            System.out.println(response);
            System.out.println("----------------------------------------");


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

     public static String dumpStream(InputStream is) {
    try {

        byte[] theBytes = new byte[is.available()];
        is.read(theBytes, 0, is.available());
        is.close();
        return new String(theBytes);
    } catch (IOException ex) {
    }
    return null;
} // ()
}  // class

You need to find out your user id and an access token from
the opengraph explorer

The following Java code (using apache http client), publishes a message on the facebook wall of the user id specified.

public class Main2 {

    public static void main(String[] args) {



        HttpClient httpclient = new DefaultHttpClient();

        try {


            String accessToken = "AAACEdEose0cBANzDaBq";

            String message = "Hey Jude, don't make it bad";

            String userId = "200501511023";

            String requestURL = "https://graph.facebook.com/"+userId+"/feed";

            HttpPost httpPost = new HttpPost( requestURL );

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("access_token", accessToken));
            nameValuePairs.add(new BasicNameValuePair("message", message));


            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));


            // Create a response handler
            ResponseHandler<String> rh = new ResponseHandler<String>() {

                public String handleResponse(HttpResponse hr) throws ClientProtocolException, IOException {
                    return "\n" + hr.getStatusLine() + "\n\n"
                        + dumpStream(hr.getEntity().getContent());
                }
            };

            System.out.println("****************************************");
            System.out.println("executing request " + httpPost.getURI());
            System.out.println("****************************************");

            String response = httpclient.execute(httpPost, rh);


            System.out.println("----------------------------------------");
            System.out.println(response);
            System.out.println("----------------------------------------");


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

     public static String dumpStream(InputStream is) {
    try {

        byte[] theBytes = new byte[is.available()];
        is.read(theBytes, 0, is.available());
        is.close();
        return new String(theBytes);
    } catch (IOException ex) {
    }
    return null;
} // ()
}  // class
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文