0

我正在尝试发布操作以邀请用户使用我的应用。我定义了一个“邀请”自定义操作,其中相关对象是预定义的“配置文件”对象。我正在尝试以一种可以发布“用户 X 邀请用户 Y”操作的方式使用它。我以前做过自定义操作,所以我知道这个练习。

我设法使用我的测试用户进行 API 调用,并且我从 API 中获得了一个新的已发布操作 ID。但是,我没有在发送方或接收方的提要或时间线上看到该操作。

重要笔记:

  • 用户是测试用户(两者)并且未提交操作,但是,在相同条件下做类似的事情(使用不同类型的对象)效果很好。
  • 对于对象 URL,我使用的是 Facebook 图形 URL (https://graph.facebook.com/xxxx)。API 似乎吃得很好。

我究竟做错了什么?

PS。如果您能想到一种更好的方式来实现邀请机制,而不是请求对话框,我愿意接受建议。需要明确的是,我没有“publish_stream”权限,但我有“publish_actions”。

附带说明:我不确定如何(或是否)通知接收者(动作对象)。

4

2 回答 2

0
make a Folder named as : Controls

Then add this: InviteControl.aspx
simply write :
<span id="invitespan" runat="server"></span>

InviteControl.ascx.cs : 

public partial class Controls_InviteControl : System.Web.UI.UserControl
{
    /// <summary>
    /// Show border or not
    /// </summary>
    public bool ShowBorder { set { showBorder = value; } }

    /// <summary>
    /// Display email section
    /// </summary>
    public bool EmailInvite { set { emailInvite = value; } }

    /// <summary>
    /// Number of rows. Allowed values are from 3 to 10. Default value is 5.
    /// </summary>
    public int Rows { set { rows = value; } }

    /// <summary>
    /// Number of columns. Allowed values are from 2,3 and 15. Default value is 5.
    /// </summary>
    public int Colums { set { colums = value; } }

    /// <summary>
    /// Set comma separated string of friend ID which you don't want to be in invite list
    /// </summary>
    public string ExcludeFriends { set { excludeFriends = value; } }

    /// <summary>
    /// IList of friend IDs which you don't want to be in invite list
    /// </summary>
    public IList<long> ExcludeFriendsList
    {
        set
        {
            if (value != null)
            {
                int i = 0;
                StringBuilder s = new StringBuilder();
                foreach (long id in value)
                {
                    i++;
                    s.Append(id.ToString());
                    if (i < value.Count)
                    {
                        s.Append(",");
                    }
                }
                excludeFriends = s.ToString();
            }
        }
    }

    /// <summary>
    /// URL where application should be redirected, after an invitation is sent.
    /// Default is application Canvas URL taken from web.config file.
    /// </summary>
    public string ActionUrl { set { actionUrl = value; } }

    /// <summary>
    /// URL where user will be redirected after the invite request is accepted.
    /// If it's not set, ActionUrl is used.
    /// </summary>
    public string AcceptUrl { set { acceptUrl = value; } }

    /// <summary>
    /// Main description which will apear on invite request
    /// </summary>
    public string Content { set { content = value; } }

    /// <summary>
    /// Application name displayed on send button and invite request title.
    /// Default is name taken from web.config file
    /// </summary>
    public string AppName { set { appName = value; } }

    /// <summary>
    /// Title of confirmation button inside invite request. Default value is 'Accept'
    /// </summary>
    public string ConfirmButtonTitle { set { confirmButtonTitle = value; } }

    /// <summary>
    /// Main title of control
    /// </summary>
    public string MainTitle { set { mainTitle = value; } }

    /// <summary>
    /// Refresh display of the control
    /// </summary>
    public void Refresh()
    {
        if (mainTitle == null) throw new Exception("Invite Friends Error:  Main Title is not set.");        
        if (content == null) throw new Exception("Invite Friends Error:  Content is not set.");

        if (confirmButtonTitle == null) throw new Exception("Invite Friends Error:  Confirm Button Title is not set.");
        if (actionUrl == null) actionUrl = Core.AppConfig.AppCanvasUrl;

        if (acceptUrl == null) acceptUrl = actionUrl;
        if (appName == null) appName = Core.AppConfig.AppName;

        StringBuilder html = new StringBuilder();
        html.Append("<fb:serverfbml ");
        html.Append("width='" + width + "'>");
        html.Append("<script type='text/fbml'>");
        html.Append("<div style='" + cssStyle + "' class='" + cssClass + "'>");
        html.Append("<fb:fbml>");
        html.Append("<fb:request-form method=\"POST\" action=\"");
        html.Append(actionUrl);
        html.Append("\" content=\"");
        html.Append(content);
        html.Append("<fb:req-choice url='");
        html.Append(acceptUrl);
        html.Append("' label='");
        html.Append(confirmButtonTitle);
        html.Append("' />\" type=\"");
        html.Append(appName);
        html.Append("\" invite=\"true\">");
        html.Append("<fb:multi-friend-selector target=\"_top\" condensed=\"false\" exclude_ids=\"");
        html.Append(excludeFriends);
        html.Append("\"  actiontext=\"");
        html.Append(mainTitle);
        html.Append("\" showborder=\"");
        html.Append(showBorder);
        html.Append("\" rows=\"");
        html.Append(rows);
        if (colums < 5) // fixing bug in FBML (if columns == 5 it renders as it as 4)
        {
            html.Append("\" cols=\"");
            html.Append(colums);
        }
        html.Append("\" email_invite=\"");
        html.Append(emailInvite);
        html.Append("\" />");
        html.Append("</fb:request-form> ");
        html.Append("</fb:fbml>");
        html.Append("</div>");
        html.Append("</script>");
        html.Append("</fb:serverfbml>");

        invitespan.InnerHtml = html.ToString();
    }

    /// <summary>
    /// Page Load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Refresh();
        }
    }


    /// <summary>
    /// Private members
    /// </summary>
    private string excludeFriends = "";
    private string actionUrl = null;
    private string acceptUrl = null;
    private string content = null;
    private string confirmButtonTitle = "Accept";
    private string appName = null;
    private string mainTitle = null;
    private bool showBorder = true;
    private bool emailInvite = true;
    private int rows = 4;
    private int colums = 4;
    private string cssStyle = "";
    private string cssClass = "";
    private int width = 625;


    /// <summary>
    /// Obsolete members/methods
    /// </summary>
    [Obsolete("You shouldn't use this property anymore. Use AppName instead")]
    public string SendButtonTitle { set { appName = value; } }
}


Then add a page : InviteFriends.aspx

copy and paste this :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InviteFriends.aspx.cs" Inherits="InviteFriends"
    EnableViewState="false" %>

<%@ Register Src="~/Controls/InviteControl.ascx" TagName="Invite" TagPrefix="cc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>
        <%= Core.AppConfig.AppName %></title>

    <script type="text/javascript">
        window.fbAsyncInit = function() {
            FB.Canvas.setAutoGrow();
        }
    </script>

</head>
<body>
    <div id="page">
        <div>
            <asp:Literal runat="server" ID="lInitFB" />
            <form id="form1" runat="server">
            <div runat="server" id="dvCanvas">
                <div id="workfield">
                    <div id="invite">
                        <cc:Invite runat="server" ID="ccInvite" ActionUrl="http://cflluxury.allsocialassets.com/InviteFriends.aspx"
                            Content="Invite to Luxury app" ConfirmButtonTitle="Confirm" MainTitle="Luxury App" />
                    </div>
                </div>
            </div>
            </form>
        </div>
    </div>
    <div id="fb-root">
    </div>

    <script src="http://connect.facebook.net/en_US/all.js"></script>

    <script>
        FB.init({
            appId: '414171951949853',
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true // parse XFBML
        });
    </script>
</body>
</html>

Then give a link to that invite page from your default page: 

<a href="InviteFriends.aspx">Invite Friend</a>

Hope it will help.
于 2012-05-16T12:25:30.820 回答
0

如果没有他们首先授权您的应用并同意事先发布这些操作,您就无法将 OG 操作发布到用户朋友的墙上。此外,接收邀请并不是行动的目的。Facebook 的政策也不允许您在一个操作中标记两个用户,除非他们实际一起执行了该操作(字面意思是在同一位置,或者实际上在您的应用程序中)。

于 2012-08-11T05:49:31.073 回答