Unable to Post Event to Page as Application

Feb 18, 2010 at 2:23 PM
Edited Feb 18, 2010 at 2:24 PM

I have spent days attempting to resolve this problem, including researching very many resources on the Web. Any help would be most appreciated, as I am completely stuck! Has anyone ever got this working?

I am using the .Net  Developer's Toolkit 3.0.

I have a Facebook Application. I also have a Facebook (fan) Page. Both created by myself.

I am trying to post Events to the Page with my Application as the poster. The Wiki indicates that this is possible by adding the page_id property to the event_info block. First problem is that the Developer's Toolkit doesn't support that property, so I was forced to use their Api interface directly. I have set the create_event permission. But whatever variation of code I try I always get a Permissions Error response.

Here is the essence of my code  (in C#):

Api api = new Api (session);

// test for permission 
var result = api.Users.HasAppPermission(Enums.ExtendedPermissions.create_event, myuserid);
 
var parameterList = new Dictionary<string, string> {
    { "method", "facebook.events.create"}
};

var dict = new Dictionary<string, string>();
    dict.Add("name", "Name");
    dict.Add("start_time", DateTime.Now.AddDays(1));
    dict.Add("end_time",  DateTime.Now.AddDays(2));
    dict.Add("page_id", mypage_id);
    dict.Add("creator", mypage_id);         
    dict.Add("category", "1");
    dict.Add("subcategory", "1"); 
    dict.Add("city", "Toronto");
    dict.Add("location", "My Place");
      
Facebook.Utility.Utilities.AddJSONAssociativeArray(parameterList, "event_info", dict);

var response = api.SendRequest (parameterList, false);

Fails!

Notes:

1. Above was hacked from code in  the Developer's Toolkit!

2. Various references disagree on the mandatory properties in event_info, so I have played safe.

John

Feb 19, 2010 at 2:29 PM
Edited Feb 19, 2010 at 2:32 PM

We are supporting this as well.  We did have to hack page_id into the Facebook Toolkit.  The two permissions we require are create_event and offline_access.  The user that you are posting with also has to be an admin on the page you are posting to.  We check like this:

 

//check that the user is an admin of the page they are trying to update
                bool isAdmin = _fbApi.Pages.IsAdmin(Convert.ToInt64(facebookPageID));
                if (!(isAdmin))
                {
                    //don't continue if you are not a page admin
                    string err = string.Format("User is not a page admin in Facebook and cannot create events);
                    throw new Exception(err);
                }

Hope this helps.

Feb 19, 2010 at 2:35 PM
Edited Feb 19, 2010 at 2:43 PM

One more thing.  The Facebook Toolkit does not support images on events so we had to hack this in as well.  I'd submit a patch but the repository doesn't work and the team never responds.  If you need this code, let me know and I'll see about sending it to you or posting it somewhere.

UPDATE: It's been a while since I was on here.  The repository works now. I'll see what I can do about updating my code and submitting a patch for the event photo.

UPDATE 2: I spoke too soon. I still can't get updated source code from the repo so not sure about patching it.

Feb 22, 2010 at 4:36 AM
cisellis wrote:

One more thing.  The Facebook Toolkit does not support images on events so we had to hack this in as well.  I'd submit a patch but the repository doesn't work and the team never responds.  If you need this code, let me know and I'll see about sending it to you or posting it somewhere.

UPDATE: It's been a while since I was on here.  The repository works now. I'll see what I can do about updating my code and submitting a patch for the event photo.

UPDATE 2: I spoke too soon. I still can't get updated source code from the repo so not sure about patching it.

 Hi cisellis,

I am creating facebook events and it is creating successfully. I want to add images to that event. Once you update the patch please post it here. Please help me regarding this.

Thanks,

Ibrahim.

Mar 22, 2010 at 3:07 PM
Edited Mar 22, 2010 at 3:31 PM

cisellis can you explain what is the hack you had ti add to the Toolkit in order to make the page_ID work?

Update:  I added this and it works fine:

in the Events.cs file, in the Create Method under the

 if (event_info.tagline != null)
{
     dict.Add("tagline", event_info.tagline);
}
add
if(event_info.creator.HasValue)
{
    dict.Add("page_id", event_info.creator.Value.ToString());
} 

 

Mar 22, 2010 at 5:13 PM

mohock: That's pretty much the same as what we added.  I think we also updated the code generation XSD but that may not be strictly necessary.

Brian