Adding an Event for Espresso on Wordpress from C# - wordpress

Working with WordPress and the Espresso Plugin for Events. I've never dealt with WP or Plugin's before, so I'm in new territory.
I am attempting to add an event and I keep getting the following error:
{"code":"rest_cannot_create_events","message":"Sorry, you are not allowed to create events. Missing permissions: ee_edit_events,ee_edit_others_events,ee_edit_private_events","data":{"status":403}}
I've gone into the WP admin pages and made sure the user I am trying to login as has all the permissions for this plugin.
The first thing I do is access the /wp-login.php page to get the Cookies:
string formVars = "";
string result = "";
string eventUrl = $"<url>/wp-login.php";
Dictionary<string, string> headers = new Dictionary<string, string>();
formVars = $"log={UserName}&pwd={Password}";
Cookie = new System.Net.CookieContainer();
AllowAutoRedirect = false;
result = PerformPost(eventUrl, formVars, true, headers);
The PerformPost uses an HttpWebRequest to send and receive.
That part seems to work and I get what looks like valid cookies.
I then do another post to /wp-json/ee/v4.8.29/events/ and pass in the body just the name of the event like EVT_name=TestEvent.
It's at this point that I get the the error mentioned above.
So a couple of questions.
1) Has anyone done this before? (Added an Event to Espresso on WordPress)
2) If Espresso doesn't like what I am feeding it, does it generate this error rather than just telling me I'm not giving it the correct information?
I've also tried using the Basic Auth plugin with the same results.
Any help is greatly appreciated.

Related

Get Facebook Warnings While Posting Via app ( Asp.net)

I've build a web app to post on my pages via page identity.
is there any method/procedure to get any kind of warnings that appear while posting images/link on my pages, like when posting regular we get captcha or other pop up messages regarding anything we post, but we don't get this when doing so via app. so is there anything that can be used to get that on app?
i use this code to post on fb
FacebookClient client = new FacebookClient(PageAccessToken);
dynamic parameters = new ExpandoObject();
parameters.message = txtTitle.Text;
parameters.link = strLink;
var PostID = client.Post("/" + PageId + "/feed", parameters);
Now When posting if there's any captcha or another messages (Warning) while posting, i wanna see it on app??
Let Me Be Clear a Little:
When u post too many posts on a page( Continuously), facebook shows captcha warnings every few posts 5-10. And When u reach a critical limit, facebook again shows captcha with warning message "You are misusing this feature", and if you continuously keep posting, fb will block u from posting. now when u post these posts via app, facebook keeps on posting without warnings/captcha's. so post on page manually=captcha popups and warning messages. post via app=no captcha/warning messages.
i want to read those messages on my app so i know if there's any warning or captcha message is shown(but ignored due to posting via app).
Whenever you make a call:
client.Post("/" + PageId + "/feed", parameters);
You get a JSON in response. I think var PostID is mis-leading. You get a JSON in reponse.
If the posting is success, you get the response as-
{
"id": "XXXXXXXXXX_YYYYYYYYYY"
}
If posting fails, you get the response as-
{
error:
{
"message": " ........ ",
"code": XXX,
"type": "......"
}
}
So you can always check for the error in the response and handle it appropriately.

I can't get my account to authorise itself using linqtotwitter

I know this has been asked many times before, but I have used info from the linqtotwitter docs and examples along with other posts on here to get this far. I can get my new app to send a tweet, but only by letting it take me to twitters authorise page and me having to click the authorise button to continue.
The app itself is authorised fine, so I don't need my password each time, it's just the use of the app that it wants permission for.
I know the reason for this is because nowhere in my code is there my access token or access token secret. I have added them in but every time I get a 401 unauthorised (invalid or expired token).
My code is as follows, perhaps you can see where I'm going wrong?
private IOAuthCredentials credentials = new SessionStateCredentials();
private MvcAuthorizer auth;
private TwitterContext twitterCtx;
public ActionResult Index()
{
credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"];
credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];
credentials.AccessToken = "MYaccessTOKENhere"; // Remove this line and line below and all works fine with manual authorisation every time its called //
credentials.OAuthToken = "MYaccessTOKENsecretHERE";
auth = new MvcAuthorizer
{
Credentials = credentials
};
auth.CompleteAuthorization(Request.Url);
if (!auth.IsAuthorized)
{
Uri specialUri = new Uri(Request.Url.ToString());
return auth.BeginAuthorization(specialUri);
}
twitterCtx = new TwitterContext(auth);
twitterCtx.UpdateStatus("Test Tweet Here"); // This is the line it fails on //
return View();
}
Here's the FAQ that has help on resolving 401 errors: http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation
A couple items that might be helpful too:
You can't tweet the same text twice - so either delete the previous tweet with the same text or change the text. All my test append DateTime.Now.ToString() to avoid this error.
The SessionStateCredentials holds credentials in SessionState. The persistence mode default for Session state is InProc, meaning that your session variables will be null if the process recycles, which will happen unpredictably. You might want to make sure that you are using either StateServer or SQL Server modes.

publish actions to facebook using open graph api and C#

I am getting the following error while publishing the facebook action using open graph api,
(Exception - #1611072) The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: post.
The actions are properly mapped to object in facebook app dashboard and i also tested the open grap object (my web page) in the debugger and there are no warnings.The meta tags in the page has been set properly.
I am using C# for publishing the actions.
Code follows:
var fb = new FacebookClient("XXX");
var parameters = new Dictionary<string, object>
{
{"og:type", "testnamespace:post"},{"og:url","http://test.sitename.com/postdetails/3247/Hello-ktm"},
{"og:title", "test post"},
{
"og:image",
"http://cdn.test.com/842-ff7c1e64-8d6f-4989-bf77-1a1f1520b39e_th.png"
}
};
var response = fb.Post("me/testnamespace:share", parameters);
Please help.Its urgent.
At least one of the following properties must be specified: post.
Looks like the name of your object you connected the action with is post.
So you will also have to give a parameter named post, containing the URL to your OG object, when publishing the action.

Can't get profile data in Application_Start

I have the following code at some point in Application_Start
MembershipUserCollection users = Membership.GetAllUsers();
foreach (MembershipUser u in users)
{
ProfileBase profile = ProfileBase.Create(u.UserName, false);
if (profile["Index"] != null)
{
// Some code
}
}
The problem is that when i try to access the profile properties I get "Request is not available in this context" httpException. I have tried using profile.GetPropertyValue but no luck also.
Why does profile need the request object and how can I get this to work?
EDIT:
I have looked into the .NET code and found that at some point SqlProfileProvider.GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc) is called, inside of which rests this string of code:
if (!current.Request.IsAuthenticated)
Apparently this will never work if not in request context. The workaround descripbed in Onur's answer will work fine.
Apparently you are trying to access request object which is not possible in your case.
Please take a look following link and apply one of workarounds if possible.
http://mvolo.com/iis7-integrated-mode-request-is-not-available-in-this-context-exception-in-applicationstart
and if you give more information what are you trying to achieve we can find another way.
You could get the "string value" properties by querying the aspnet_Profiles table and parsing the string.
SELECT [UserName]
,[PropertyNames]
,[PropertyValuesString]
FROM [aspnet_Profile]
LEFT JOIN [aspnet_Users] on [aspnet_Users].UserId = [aspnet_Profile].UserId
The PropertyValuesString can be parsed with a bit of code. This link should explain the format in detail https://msdn.microsoft.com/en-us/library/aa478953.aspx#persistence_format.

Drupal node.save and JSONP

I am having an issue with call Drupal node.save using MooTool's JSONP. Here is an example.
Here is my request:
callback Request.JSONP.request_map.request_1
method node.save
sessid 123123123123123
node {"type":"blog","title":"New Title","body":"This is the blog body"}
Here is my result
HTTP/1.0 500 Internal Server Error
I got this working before, but i used AMFPHP and was able to send objects to drupal. I am assuming that this has to do with Drupal expecting an object, but since it is a GET it gets transformed as a string. Is there any way of getting around this with out hacking the code?
Here is my code:
$('newBlogSubmit').addEvent('click', function()
{
var node = {
type : "blog",
title:"New Title",
body :"This is the blog body"
}
var string = JSON.encode(node);
string.escapeRegExp()
var sessID = _sessID;
DrupalService.getInstance().node_save(string, sessID, drupal_handleBlogSubmit);
});
My Drupal Service JS Code:
//NODE
DrupalService.prototype.node_save = function(node, sessid, callback){
var dataObj = {
method : "node.save",
sessid : sessid,
node : node
}
DrupalService.getInstance().request(dataObj, callback);
}
//SEND REQUEST AND CALLBACK FUNCTION
DrupalService.prototype.request = function(dataObject, callback){
new JsonP('http://myDrupalSite.com/services/json', {data: dataObject,onComplete: callback}).request();
}
I am trying to connect the dots, but not too familiar with Drupal, but i would guess all I need to do is turn the string back into an object. Any ideas where I should be looking, or if there is an existing patch?
A first question could be why you use mootools since Drupal comes with jQuery and use it extensively throughout the different modules and Drupal core itself.
Anyways I don't know mootools so can't help you there, but if your request in ending in a internal server error, you have a problem with your drupal code or your js code. So even if I knew exactly what you were doing, I couldn't tell you the problem without looking at the drupal code for your http://myDrupalSite.com/services/json callback.
In general, what you want to make sure is:
You make a POST request, as drupal will cache get's and the semantic of this, is that you are posting data - the node - to the server.
Your data should be sent as post params, this will make them end up in the PHP $_POST variable
Your callback should validate the data and act accordingly, creating a node when the data is intact. You don't need session id's since the script will have the same session the browser has.
I've answered a similar question in detail, which was about altering a field instead of saving a node, but much of the work is still the same. You can take a look on the post, although this is with jQuery and not Mootools.

Resources