我正在尝试发布邀请用户访问我的应用的操作。我定义了一个“邀请”自定义操作,其中相关对象是预定义的“配置文件”对象。我试图以我可以发布“用户X邀请用户Y”操作的方式使用它。我以前做过自定义操作,所以我知道这个练习。
我设法使用我的测试用户进行API调用,并且我从API获取了新发布的操作ID。但是,我没有在发件人或收件人提要或时间表中看到该操作。
重要说明:
我做错了什么?
PS。如果你能想到一种更好的实现邀请机制的方法,除了请求对话框,我愿意接受建议。要清楚,我没有“publish_stream”权限,但我确实有“publish_actions”。
旁注:我不确定接收者(行动对象)将如何(或是否)得到通知。
答案 0 :(得分: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.
答案 1 :(得分:0)
如果没有他们首先授权您的应用以及同意事先发布这些操作,您就无法将OG操作发布到用户的朋友的墙上。此外,接收邀请不是针对的行为。 Facebook的政策也不允许您在行动中标记两个用户,除非他们实际上一起执行该操作(确切地说是在同一个位置,或者几乎在您的应用中)。