Facebook:发送应用邀请

发布于 2024-11-08 20:24:30 字数 60 浏览 0 评论 0原文

如何发送使用具有 Graph API 的应用程序的邀请?我查看了参考资料,找不到合适的东西。有什么线索吗?

How can I send an invitation to use an app with Graph API? I looked at the reference, and can't find something that fits. Any clue?

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

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

发布评论

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

评论(3

戈亓 2024-11-15 20:24:30

HTML/javascript 示例:

<html>
  <head>
  <title>My Great Website</title>
  </head>
  <body>
  <div id="fb-root"></div>
  <script src="http://connect.facebook.net/en_US/all.js">
  </script>
  <script>
    FB.init({ 
      appId:'YOUR_APP_ID', cookie:true, 
      status:true, xfbml:true 
    });

    FB.ui({ method: 'apprequests', 
      message: 'Here is a new Requests dialog...'});
  </script>
  </body>
</html>

您可以将 javascript 关联到链接的单击事件等。

您可以在此处找到详细信息:
http://developers.facebook.com/blog/post/464/

A HTML/javascript example:

<html>
  <head>
  <title>My Great Website</title>
  </head>
  <body>
  <div id="fb-root"></div>
  <script src="http://connect.facebook.net/en_US/all.js">
  </script>
  <script>
    FB.init({ 
      appId:'YOUR_APP_ID', cookie:true, 
      status:true, xfbml:true 
    });

    FB.ui({ method: 'apprequests', 
      message: 'Here is a new Requests dialog...'});
  </script>
  </body>
</html>

You can associate the javascript to click event of a link, etc.

You can find the details here:
http://developers.facebook.com/blog/post/464/

软糖 2024-11-15 20:24:30

如果您需要使用restfb,正如我从您的标签中获得的那样,您可以尝试以下操作:

这是一个自包含的junit测试,用于检索身份验证令牌并发布apprequest。不需要用户生成 auth_token,但您只能将这样的应用程序请求发送给已经授权您的应用程序的用户。

依赖项是 JUnit、Commons HttpClient 和 Restfb 本身。

package com.apprequesttest;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.junit.Test;

import com.restfb.DefaultFacebookClient;
import com.restfb.Facebook;
import com.restfb.FacebookClient;
import com.restfb.Parameter;
import com.restfb.types.FacebookType;

public class AppRequestTest
{
    @Test
    public void testAppRequest() throws Exception
    {
        String appId = "YOUR_APP_ID";
        String appSecret = "YOUR_ACCESS_TOKEN";
        String tokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&client_secret=" + appSecret
                + "&grant_type=client_credentials";
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod(tokenUrl);

        client.executeMethod(method);
        String rawAccessToken = new String(method.getResponseBody());

        String accessToken = rawAccessToken.split("=")[1];

        FacebookClient facebookClient = new DefaultFacebookClient(accessToken);

        String apprequestCall = "TARGET_USER_ID/apprequests";

        AppRequestResponse apprequest = facebookClient.publish(apprequestCall,
                                                               AppRequestResponse.class,
                                                               Parameter.with("message", "BANANAMSG"),
                                                               Parameter.with("data", "BANANADATA"));

        System.out.println(apprequest.request);
        System.out.println(apprequest.to);

    }

    /**
     * Couldn't find any beans that would acomodate this response on restfb so we create our own here
     * Looks like "to" is an array but this works well enough for the sake of the example 
     */
    public static class AppRequestResponse extends FacebookType
    {
        private static final long serialVersionUID = 1L;

        public AppRequestResponse()
        {
            // Empty
        }

        @Facebook
        public String request;

        @Facebook
        public String to;
    }
}

If you need to use restfb, as I got from your tags, you can try this:

This is a self contained junit test that retrieves the authentication token and posts an apprequest. No user generated auth_token is required but you can only send apprequests like this to users that already have authorized your app.

Dependencies are JUnit, Commons HttpClient and restfb itself.

package com.apprequesttest;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.junit.Test;

import com.restfb.DefaultFacebookClient;
import com.restfb.Facebook;
import com.restfb.FacebookClient;
import com.restfb.Parameter;
import com.restfb.types.FacebookType;

public class AppRequestTest
{
    @Test
    public void testAppRequest() throws Exception
    {
        String appId = "YOUR_APP_ID";
        String appSecret = "YOUR_ACCESS_TOKEN";
        String tokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&client_secret=" + appSecret
                + "&grant_type=client_credentials";
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod(tokenUrl);

        client.executeMethod(method);
        String rawAccessToken = new String(method.getResponseBody());

        String accessToken = rawAccessToken.split("=")[1];

        FacebookClient facebookClient = new DefaultFacebookClient(accessToken);

        String apprequestCall = "TARGET_USER_ID/apprequests";

        AppRequestResponse apprequest = facebookClient.publish(apprequestCall,
                                                               AppRequestResponse.class,
                                                               Parameter.with("message", "BANANAMSG"),
                                                               Parameter.with("data", "BANANADATA"));

        System.out.println(apprequest.request);
        System.out.println(apprequest.to);

    }

    /**
     * Couldn't find any beans that would acomodate this response on restfb so we create our own here
     * Looks like "to" is an array but this works well enough for the sake of the example 
     */
    public static class AppRequestResponse extends FacebookType
    {
        private static final long serialVersionUID = 1L;

        public AppRequestResponse()
        {
            // Empty
        }

        @Facebook
        public String request;

        @Facebook
        public String to;
    }
}
魔法少女 2024-11-15 20:24:30

http://developers.facebook.com/docs/reference/dialogs/requests/

您可以使用上面链接中所述的对话框

http://developers.facebook.com/docs/reference/dialogs/requests/

You can use dialogs as described in the above link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文