Spring Social Twitter Authenticaion in asp.net - asp.net

I'm designing a website using forms asp.net
I would like this website to view tweets for a from a twitter account timeline using spring social twitter API
the problem is when I i run the web page it show this error
The Twitter REST API v1 is no longer active. Please migrate to API
v1.1. https://dev.twitter.com/docs/api/1.1/overview.
I'm sure that I have the latest version of the library as it works fine with there console application sample code but they neither provide a sample for AS.NET forms nor a proper documentation
I'm really lost and I can't figure how to use it
anyway here's my code and I would really appreciate any help
string consumerKey = //my kry;
string consumerKeySecret = //my key secret;
string accessToken = //my token;
string accessTokenSecret = //my token secret;
ITwitter twitter = new TwitterTemplate(consumerKey, consumerKeySecret, accessToken, accessTokenSecret);
IList<Tweet> tweets = twitter.TimelineOperations.GetUserTimeline();
foreach (var tweet in tweets)
lbl.Text = lbl.Text + "\n" + tweet;

The API you are using seems to be deprecated.
I am personally used Tweetinvi for lots of developments related with Twitter and lots of features are already implemented.
Also it is compatible with Twitter 1.1.
Here is how to get the timeline of the connected user:
var user = User.GetLoggedUser();
var timeline = user.GetUserTimeline();

Related

Adding an Event for Espresso on Wordpress from C#

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.

Two Factor Authentication using Google Authenticator in own asp.net project?

Hello I have created own asp.net project (Not MVC). Now I want to implement Two Factor Authentication using Google Authenticator. So when ever user get register user will get key or get QR image and setup with it's android phone. And for login they need key from google authenticator app.
I got few MVC code in asp.net. I need steps to how integrate in asp.net application (Not MVC) Please guide how can i implement this any sample will be appreciated.
Thanks
To Add Google authentication you need the following
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
using System.Web.Profile;
using System.Web.Security;
using Google.Authenticator;
To get the Google.Authenticator; check here https://www.nuget.org/packages/GoogleAuthenticator
now setting up the Google authentication.
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
var setupInfo = tfa.GenerateSetupCode("Name of the app", "More info ABout the App", "SuperSecretKeyGoesHere", 300 , 300//the width and height of the Qr Code);
string qrCodeImageUrl = setupInfo.QrCodeSetupImageUrl; // assigning the Qr code information + URL to string
string manualEntrySetupCode = setupInfo.ManualEntryKey; // show the Manual Entry Key for the users that don't have app or phone
Image1.ImageUrl = qrCodeImageUrl;// showing the qr code on the page "linking the string to image element"
Label1.Text = manualEntrySetupCode; // showing the manual Entry setup code for the users that can not use their phone
you can change the SuperSecretKeyGoesHere to any value that you want, but make sure it has more than 10 character otherwise the manual entry key that is generated will not work.
Now you can check the user input with text box and button click
this bit will look at the user entry and see if its ok
string user_enter=TextBox1.Text;
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
bool isCorrectPIN = tfa.ValidateTwoFactorPIN("SuperSecretKeyGoesHere", user_enter);
if (isCorrectPIN == true)
{
Label2.Text = "i am cool";
}
else
{
Label2.Text = "i am Fool";
}
Old question but I've blogged about your case exactly, you can read the post: Two Factor Authentication in ASP.NET Web API & AngularJS using Google Authenticator
Hope this answers your question.

How to get all users from aweber list in asp.net?

I am developing web application (using VS2010 and asp.net,c#) that gets all aweber users list. I am using following code to achieve it.
i am using this useful document. as per this document i did following things..
created account in aweber labs https://labs.aweber.com/
created "test" app
Use the "consumerKey" and "consumerSecret" code which is given by aweber team.
used following code
String consumerKey = "Afdgdfgdgfgdfll";
String consumerSecret = "zDKexfgdfgdfQqlKh5KD";
API api = new API(consumerKey, consumerSecret);
api.CallbackUrl = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/Authorize.aspx";
api.get_request_token();
HttpContext.Current.Session.Add("oauth_token", api.OAuthToken);
HttpContext.Current.Session.Add("oauth_token_secret", api.OAuthTokenSecret);
api.authorize();
i am getting null value "OAuthToken". If any solution then let me guide.
Thanks in advance. !!
Check out http://aweber.codeplex.com/
This will save you a lot of work.

API (Service) to work for both Windows Phone and Website

I created(in last stage) a ASP.NET website which requires database communications, So we created WCF services to connect to the database. If there is a Select statement those service returns DataTable.
Services are working fine and website also working fine
At the time of API creation i don't know that windows phone sdk does not support the DataTables.
I read some where that Windows Phone SDK doesn't support DataTable, i checked in my Visual Studio also there is no class called DataTable in System.Data namespace.
I am new to Windows Phone.
But now we want to create a WINDOWS PHONE APP which also works same as Website, so we want to use the existing API(WCF Service).
is there is any way to accomplish this task. most of the methods return type is DataTable.
we don't want to create two API's(means services). What should I do?
How to create a Service which works for both Windows Phone and Website.
we are ready to change the change the API and according to that ready to update Website also?
thanks
Just changed the API to return Stream instead of DataTable
System.IO.StringWriter reader = new System.IO.StringWriter();
dt.WriteXml(reader, XmlWriteMode.WriteSchema);//dt is datatable
return reader;
in website small minor changes, reading the stream and assign it to a datatable
StringReader xmlReader = new StringReader(stream);
DataTable dt = new DataTable();
dt.ReadXml(xmlReader);
Update:
This approach is not suggestible(this was my first web service application), I suggest to use JSON/XML responses(with returning DTOs) instead of returning DataTable..
Following links might land you in right direction.
http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
http://mono.servicestack.net/ServiceStack.Hello/
Not sure why you used datatable. Do you mean dataset?
They are all XML under the covers. Try parsing them. Try something like this:
var resultNewDataSet = XElement.Parse(xmlContent);
var result = resultNewDataSet.Descendants("Table")
.Select(t => new
{
aaa = t.Descendants("aaa").First().Value,
bbb = t.Descendants("bbb").First().Value
});
foreach (var res in result)
{
System.Diagnostics.Debug.WriteLine("aaa: " + res.aaa + " / bbb: " + res.bbb);
}

Twitter Library for ASP.NET MVC that implements REST API

I been looking for a twitter lib for my ASP.NET NET MVC 3 software, but I need to implement the REST API functions that I nor found in Twitter Helper or Twitterizer. Rest API allow me to use a Find People query.
There is another one could solve my problem?
My suggestion would be to try looking into a library, such as TweetSharp that already has wrappers around a substantial amount of the Twitter API methods. If that doesn't work for you, consider writing your own wrapper around the methods you need using libraries such as HammockRest or RestSharp that have support for working with http, oauth and other such features that may assist you.
Looking better in Twitterizer I found what I need, perform Search People, and other functions. I recommend Twitterizer to use twitter in ASP.NET MVC 3, ´cause the oAuth process has a better code.
Here the Sample code to peform Search People in twitter using Twitterizer :
UserSearchOptions options = new UserSearchOptions();
options.NumberPerPage = 40;
options.Page = 1;
TwitterResponse<TwitterUserCollection> usersResponse = TwitterUser.Search(tokens,pesquisa.Conteudo,options);
if (usersResponse.Result == RequestResult.Success)
{
StringBuilder list = new StringBuilder();
foreach (var u in usersResponse.ResponseObject)
{
list2.Append(u.Name + "-" + u.Id);
}
ViewBag.Result_Twitter = list.ToString();
}

Resources