1

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?
4

2 回答 2

0

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

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

  • 打电话https://graph.facebook.com/oauth/authorizeclient_id=<your app's client_id>&redirect_uri=<your redirect URU>。如您所见,您必须传输您的 client_id 和一个 URI,Facebook 将在该过程结束时将其重定向。您还可以传输数据参数,该参数将在整个过程中保持不变。有助于跟踪用户。
  • callhttps://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>代码参数由上一步中对重定向 URI 的调用给出
  • call https://graph.facebook.com/me?access_token=<access_token>,使用先前重定向返回的临时 access_token ,然后您将获得真正的access_token

更多信息在这里:

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

于 2010-12-08T17:55:34.040 回答
0

您需要从opengraph 资源管理器中找到您的用户 ID 和访问令牌

以下 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
于 2013-02-14T10:46:09.943 回答