Twitterizer get user information - asp.net-mvc-3

I have a questions on using Twitterizer
I want to get the TwitterUser model for getting the user's information from the response request on Twitter, but i don't know the way.
This is my code:
public ActionResult Logon(string oauth_token, string oauth_verifier, string ReturnUrl)
{
if (string.IsNullOrEmpty(oauth_token) || string.IsNullOrEmpty(oauth_verifier))
{
UriBuilder builder = new UriBuilder(this.Request.Url);
builder.Query = string.Concat(
builder.Query,
string.IsNullOrEmpty(builder.Query) ? string.Empty : "&",
"ReturnUrl=",
ReturnUrl);
string token = OAuthUtility.GetRequestToken(
ConfigurationManager.AppSettings["TwitterConsumerKey"],
ConfigurationManager.AppSettings["TwitterConsumerSecret"],
builder.ToString()).Token;
//return Redirect(OAuthUtility.BuildAuthorizationUri(token, true).ToString());
Response.Redirect(string.Format("http://twitter.com/oauth/authenticate?oauth_token={0}&force_login=true", token), true);
}
var tokens = OAuthUtility.GetAccessToken(
ConfigurationManager.AppSettings["TwitterConsumerKey"],
ConfigurationManager.AppSettings["TwitterConsumerSecret"],
oauth_token,
oauth_verifier);
OAuthTokens accessToken = new OAuthTokens();
accessToken.AccessToken = tokens.Token;
accessToken.AccessTokenSecret = tokens.TokenSecret;
accessToken.ConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"];
accessToken.ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"];
//TwitterUser u =
TwitterUser myTwitterUser = ..............
..............
}
I already get the OAuthTokens.After the "........." i don't know what to do next to get the information for the user.
Anyone can help me.Thansk a lot

Did you try looking at the documentation:
TwitterResponse<TwitterUser> myTwitterUser = TwitterUser.Show(accessToken, "twit_er_izer");

Related

active directory with xamarin method

I wrote the following code to find out if the user logging has an account at active directory so i may allow him to proceed and it's working fine:
public bool AuthenticateUser(string domain, string username, string password, string LdapPath)
{
string domainAndUsername = domain + #"\" + username;
DirectoryEntry entry = new DirectoryEntry(LdapPath, domainAndUsername, password);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
and it works great, the only problem is that i need to make the same thing using xamarin forms , how may I?
DirectorySearcher is a class that you would use from a server API/code.
I suggest you to create a Web API that would do the same job and that will be called by your Xamarin application.

IBM Filenet P8 : How can i get the localized display names of choice list items

I am using the following code snippet to retrieve choice items for a specific choice list
Map<Serializable, Serializable> items = new HashMap<Serializable, Serializable>();
Iterator<Choice> choiceIterator = choiceList.get_ChoiceValues().iterator();
while(choiceIterator.hasNext()){
Choice choice = choiceIterator.next();
if(choice.get_ChoiceType() == ChoiceType.INTEGER){
itemKey = choice.get_ChoiceIntegerValue();
}else{
itemKey = choice.get_ChoiceStringValue();
}
items.put(itemKey, ((LocalizedStringImpl)choice.get_DisplayNames().get(0)).get_LocalizedText());
}
but get_LocalizedText() method just get the value with locale en_us. So what if i want to get other locales i.e ar_eg?
Thanks in advance.
You need to call get_LocaleName() method on the LocalizedString object and find out if this is the right locale you are looking for. Here is sample code:
LocalizedStringList lsList = choice.get_DisplayNames();
Iterator<LocalizedString> dit= lsList.iterator();
boolean lnFound = false;
while(dit.hasNext())
{
LocalizedString ls = dit.next();
String ln = ls.get_LocaleName();
String lt = ls.get_LocalizedText();
if(_locale.equalsIgnoreCase(ln))
{
ls.set_LocalizedText(_value);
lnFound = true;
}
}

What is the magento url for posting SOAP request

Below is my code
WebClient wc = new WebClient();
using(var response = wc.OpenRead("http://templatebar.com/QA/performancetesting/enterprise1_10_0_2/magento/index.php/api/v2_soap?wsdl=1"))
{
StreamReader sr = new StreamReader(response);
string result = sr.ReadToEnd();
}
var loginRequest = string.Format(XElement.Load(AppDomain.CurrentDomain.BaseDirectory + #"XMLFiles\login.xml").ToString(),"apikey","apipassword");var loginRequest = string.Format(XElement.Load(AppDomain.CurrentDomain.BaseDirectory + #"XMLFiles\login.xml").ToString(),"admin","abcd.1234");
var response1 = wc.UploadString("", loginRequest);
My question is what should be the "address" in UploadString function so that the login request gets the desired result i.e,Magento Session id
If I use this "http://templatebar.com/QA/performancetesting/enterprise1_10_0_2/magento/index.php/api/v2_soap?wsdl=1"
URL again then I get the list of wsdl services available,which is the same as in response variable.
Please Help,
Thanks.
According to the provided wsdl, the endpoint location is: http://templatebar.com/QA/performancetesting/enterprise1_10_0_2/magento/index.php/api/v2_soap/index/
(source: check the wsdl:service location for it. The url is written in the location-element)

Got NullReferenceException when Unit testing Controller

I am working on Unit testing the MVC3 site using NUnit, MvcContrib.TestHelper package but I am facing the exception "Object reference not set to an instance of an object" when my test method accesses the controller having TryUpdateModel. I dont know what to do to pass the test. please help me in this.
I am also giving a code for that :
Action from Controller which test method calls, is given below :
public JsonResult AddPatient()
{
bool returnStatus;
string returnErrorMessage;
List<string> returnMessage;
PatientBLL patientBLL = new PatientBLL();
Models.PatientViewModel patientViewModel = new Models.PatientViewModel();
TryUpdateModel(patientViewModel);
Patient patient = patientBLL.AddPatient(
patientViewModel,
out returnMessage,
out returnStatus,
out returnErrorMessage);
patientViewModel.UpdateViewModel(patient, typeof(Patient).GetProperties());
patientViewModel.ReturnMessage = returnMessage;
patientViewModel.ReturnStatus = returnStatus;
return Json(patientViewModel);
}
and the test method which calls the above action is given below :
[Test]
public void Test_AddPatient()
{
TestControllerBuilder builder = new TestControllerBuilder();
string uniquePatientKey = GenerateUniqueID();
builder.Form["MedicalID"] = uniquePatientKey;
builder.Form["SocialSecurityNumber"] = uniquePatientKey;
builder.Form["FirstName"] = "Khushi";
builder.Form["LastName"] = "Maahi";
builder.Form["AddressLine1"] = "ABCD";
builder.Form["AddressLine2"] = "Technologies";
builder.Form["City"] = "OOna";
builder.Form["State"] = "UP";
builder.Form["ZipCode"] = "98456-7329";
builder.Form["PhoneNumber"] = "(425)882-8080";
builder.Form["DateOfBirth"] = "10/28/1987";
builder.Form["PatientDateOfBirth"] = "10/28/1987";
builder.Form["EffectiveDate"] = "01/01/1995";
builder.Form["PatientEffectiveDate"] = "01/01/1995";
PatientController patientController = builder.CreateController<PatientController>();
JsonResult jsonResult = (JsonResult)patientController.AddPatient();
dynamic jsonData = jsonResult.Data;
string jsonMessage=Convert.ToString(jsonData.ReturnMessage);
Assert.AreEqual(jsonData.ReturnStatus, true );
Assert.Greater(jsonData.PatientID, 0);
}
Please give me the solution for my probelm.
You have a null somewhere in patientViewModel. Can you post that type here? This could be a problem with mixing models and view models.

How to perform a get request with RestSharp?

I'm having trouble figuring out how to make a GET request using RestSharp on Windows Phone 7. All of the examples show making a POST request, but I just need GET. How do I do this?
GET is the default method used by RestSharp, so if you don't specify a method, it will use GET:
var client = new RestClient("http://example.com");
var request = new RestRequest("api");
client.ExecuteAsync(request, response => {
// do something with the response
});
This code will make a GET request to http://example.com/api. If you need to add URL parameters you can do this:
var client = new RestClient("http://example.com");
var request = new RestRequest("api");
request.AddParameter("foo", "bar");
Which translates to http://example.com/api?foo=bar
What you're looking for is located here.
The code snippet that covers your scenario is below (request.Method should be set to Method.GET):
public void GetLabelFeed(string label, Action<Model.Feed> success, Action<string> failure)
{
string resource = "reader/api/0/stream/contents/user/-/label/" + label;
var request = GetBaseRequest();
request.Resource = resource;
request.Method = Method.GET;
request.AddParameter("n", 20); //number to return
_client.ExecuteAsync<Model.Feed>(request, (response) =>
{
if (response.ResponseStatus == ResponseStatus.Error)
{
failure(response.ErrorMessage);
}
else
{
success(response.Data);
}
});
}

Resources