upload image to twitter with twitterizer - asp.net

I try to upload image with my tweet in twitterizer component.I send tweet without any error but UpdateWithMedia Has Error.
I think this happen because My Request Url Is "https://upload.twitter.com/1/statuses/update_with_media.json" while Shoujd be "https://upload.twitter.com/1.1/statuses/update_with_media.json".
How can i change My RequestUrl.
My Contetnt Error is : "{"errors":[{"message":"The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.","code":64}]}"
I see many solution in stackoverflow But it was not any thing to solve this problem
var oauth_consumerkey = "UEI02iC13cR8o8rgNyLpBpOmW";
var oauth_consumersecret = "RaTQoZaxq51eHR51TbTKK762eSu5u5s7FoPPswyWMJlscuC6j0";
const string callbackurl = "http://localhost:2008/WebForm1.aspx";
if (Request["oauth_token"] == null)
{
OAuthTokenResponse reqtoken = OAuthUtility.GetRequestToken(
oauth_consumerkey,
oauth_consumersecret,
callbackurl);
Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", reqtoken.Token));
}
else
{
string requesttoken = Request["oauth_token"].ToString();
string pin = Request["oauth_verifier"].ToString();
var token = OAuthUtility.GetAccessToken(
oauth_consumerkey,
oauth_consumersecret,
requesttoken,
pin);
OAuthTokens accesstoken = new OAuthTokens()
{
AccessToken = token.Token,
AccessTokenSecret = token.TokenSecret,
ConsumerKey = oauth_consumerkey,
ConsumerSecret = oauth_consumersecret
};
byte[] photo = ImageToByteArray("C:\\black_arrow.png");
TwitterResponse<TwitterStatus> response = TwitterStatus.UpdateWithMedia(accesstoken, "Testing!! Send Image", photo, new StatusUpdateOptions() { UseSSL = true, APIBaseAddress = "http://api.twitter.com/1.1/" });
if (response.Result == RequestResult.Success)
{ Response.Write("OK"); }
else
{ Response.Write("Faild"); }
}

solved,
I've used the latest version of which was in Nuget, apparently has a problem.
This time, instead of using these tools,i use the open-source project twittrizer from git and added as reference to the project and my problem was solved.
many Thanks to #DigitallyBorn, who had helped on this subject.
get open source twittrizer from www.twitterizer.net

Related

How to Read barcode image in Xamarin forms

I am trying to read the text from a QRcode image on my mobile app. I am using Xamarin.Forms with ZXing NuGet package.
I have been able to get the file using Xamarin.Essentials FilePicker. But I don't know how to actually read the barcode. I have looked at some stackoverflow solutions and they all seem to be Xamarin.Android based (using BinaryBitmap objects). I need a solution that can work for iOS and UWP as well. Here is what I have so far:
string file = "";
var filePickerOptions = new PickOptions
{
PickerTitle = "Select Barcode Image",
FileTypes = FilePickerFileType.Images
};
var result = await FilePicker.PickAsync(filePickerOptions);
if (result != null)
{
file = result.FullPath;
var res = Decode(file, BarcodeFormat.QR_CODE);
Console.WriteLine(res.Text);
}
public Result Decode(string file, BarcodeFormat? format = null, KeyValuePair<DecodeHintType, object>[] aditionalHints = null)
{
var r = GetReader(format, aditionalHints);
/* I need some function here that will allow me to get the BinaryBitmap from the image file path or something along those lines.*/
var image = GetBinaryBitmap(file);
var result = r.decode(image);
return result;
}
MultiFormatReader GetReader(BarcodeFormat? format, KeyValuePair<DecodeHintType, object>[] aditionalHints)
{
var reader = new MultiFormatReader();
var hints = new Dictionary<DecodeHintType, object>();
if (format.HasValue)
{
hints.Add(DecodeHintType.POSSIBLE_FORMATS, new List<BarcodeFormat>() { format.Value });
}
if (aditionalHints != null)
{
foreach (var ah in aditionalHints)
{
hints.Add(ah.Key, ah.Value);
}
}
reader.Hints = hints;
return reader;
}
https://github.com/Redth/ZXing.Net.Mobile/issues/981. This thread solved it for me. Credit to #jason for this response.

xamarin.forms Sharing Image AND text (body, not title)

I am using this sharing function:
public static async void ShareImageAndText(string text, string image)
{
var fn = "pic.png";
var file = Path.Combine(FileSystem.CacheDirectory, fn);
File.WriteAllBytes(file, Convert.FromBase64String(image));
await Share.RequestAsync(new ShareFileRequest()
{
Title = text,
File = new ShareFile(file)
});
}
This shares an image to whereever I please, but the text "title" only appears if I share to email. If I share to whatsapp for instance, it will only give the image. But since I also want to share a text with an uri in it, this option doesnt work.
Who knows how to share a file AND a text in the same request?
Thanks
Having the same problem, I was unable of resolving it using the Xamaring.Essentials.Share. So, I created in my Xamarin Forms App a Page with the Image and Text that I need to send, and take a screenshot of it using Screenshot https://learn.microsoft.com/en-us/xamarin/essentials/screenshot and saving it to File. Then just send it.
//Take a screenshot from this page to a file
string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var File_Path = System.IO.Path.Combine(path, "Screenshot.png");
var screenshot = await Screenshot.CaptureAsync();
var stream = await screenshot.OpenReadAsync(ScreenshotFormat.Png);
using (var fileStream = System.IO.File.Create(File_Path))
{
stream.Seek(0, System.IO.SeekOrigin.Begin);
stream.CopyTo(fileStream);
}
await Share.RequestAsync(new ShareFileRequest
{
Title = "Some Title",
File = new ShareFile(File_Path)
});

Google api 3 returning nothing when WEB APi is published

I have made a simple ASP.NET Web API that gets events from a shared google calendar, and serves them to me in json. When i fire it up from localhost i get 104 events returned: but when I've published it to my IIS server, the array contains no elements. I can't debug on it, but i get an empty array presented:
I have made an app on https://console.developers.google.com/ and added both localhost and http://domainname.dk/oauthcallback to it.
My code:
public void GetFixedEvents()
{
const string calendarId = "xxxxxxxxxxxxxxxx#group.calendar.google.com";
try
{
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = clientId,
ClientSecret = clientSecret,
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None).Result;
var service = new CalendarService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "CalendarTest",
});
var queryStart = DateTime.Now;
var queryEnd = queryStart.AddYears(1);
var query = service.Events.List(calendarId);
query.TimeMin = queryStart;
query.TimeMax = queryEnd;
query.SingleEvents = true;
var events = query.Execute().Items;
foreach (var item in events)
{
var tempEvent = new PubEvent
{
Title = item.Summary,
Description = item.Description ?? "None",
Start = item.Start.DateTime,
End = item.End.DateTime,
EventType = item.Summary.Contains("Ladies") ? EventType.LadiesNight : EventType.StudentNight
};
_pubEvents.Add(tempEvent);
}
}
catch (Exception e)
{
Console.WriteLine("Exception encountered: {0}", e.Message);
}
}
Can anyone help? Is it a problem with redirect uri? I have tried adding all the ones I can possibly think of. Is there any way to log the call to the google api?

Facebook Credits callback in a mobile web application

I'm trying to create a Facebook Mobile Application using asp.net and MVC3 and integrate Facebook Credits as a payment method. First of all, taking the recent annoucements into consideration, is it now possible to have a mobile web application that accepts Facebook Credits?
If so, I've taken the example provided in the following post
http://www.m-webs.com/blog_facebookcredits.html
And implemented the following Controller action:
public JsonResult CallBack()
{
string fborder_info = Request.Form["order_info"];
string fborder_id = Request.Form["order_id"];
string fbmethod = Request.Form["method"];
if (fbmethod == "payments_get_items")
{
fborder_info = fborder_info.Substring(1, (fborder_info.Length - 2)); // remove the quotes
ulong credscost = 2; // Price of purchase in facebook credits
var theItem = new FacebookBuyItem()
{
item_id = 123456789,
description = "Own yours today!",
price = credscost,
title = "Digital Unicorn",
product_url = "http://www.facebook.com/images/gifts/21.png",
image_url = "http://www.facebook.com/images/gifts/21.png"
};
var res = new Dictionary<string, object>();
res["method"] = fbmethod;
res["order_id"] = fborder_id;
res["content"] = new object[] { theItem };
var jss = new JavaScriptSerializer();
var ob = jss.Serialize(res);
ob = ob.Replace("#$", #"\/".Replace("//", #"\/"));
return Json(ob, JsonRequestBehavior.AllowGet);
}
return null;
}
I've verified that the callback is being requested by facebook, and I've also captured the response being sent back, which appears to contain all of the required information to display the purchase dialog, but I'm still getting the following error message:
API Error Code: 1151
API Error Description: Sorry, but this app may not be eligible to accept Facebook Credits. If this app has accepted credits before, please try again.
Error Message: Invalid Application
and when tested from a mobile browser:
Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.
I've also noticed that my callback is being requested twice which doesn't seem right either.
Any insight into how to get my integration up and running would be greatly appreciated. My Facebook AppId is 177876855621874
Thanks.
Update: So I played around with the examples given and reverted back to webforms in order to test the example given at http://www.m-webs.com/blog_facebookcredits.html. In order to get this solution working in an asp.net MVC3 application I had to change the action type to HttpResponse instead of JsonResult which makes sense as the JsonResult leaves elements out that would normally be included in a HttpResponse.
So the Controller Action ended up looking like this:
[HttpPost]
public HttpResponse CallBack()
{
if (Request.Form["signed_request"] != null)
{
var decodeFbSignedRequest = FacebookSignedRequest.Parse(FacebookApplication.Current.AppSecret,
Request.Form["signed_request"]);
LogHelper.MicroLogMsg("SIGNED REQUEST DECODE:: " + decodeFbSignedRequest.Data);
}
string fborder_id = Request.Form["order_id"];
string fbmethod = Request.Form["method"];
string fborder_info = Request.Form["order_info"]; // Use this to look up a product on the database..
if (fbmethod == "payments_get_items")
{
int credscost = 2; // Price of purchase in facebook credits
var theItem = new FacebookBuyItem()
{
item_id = "123456AA",
description = "[Test Mode] Own yours today!",
price = credscost,
title = "[Test Mode] Digital Unicorn",
product_url = #"http:\/\/www.facebook.com\/images\/gifts\/21.png",
image_url = #"http:\/\/www.facebook.com\/images\/gifts\/21.png"
};
// Return the initial response to FB
//------------------------------------------
var res = new Dictionary<string, object>();
res["method"] = fbmethod;
res["content"] = new object[] { theItem };
var jss = new JavaScriptSerializer();
string ob = jss.Serialize(res);
LogHelper.MicroLogMsg(ob);
Response.ContentType = "application/json";
Response.Write(ob);
Response.End();
}
return null;
}
I hope this helps out anyone doing an MVC3 implementation for Facebook Credits.

language option in reCAPTCHA ASP.NET plugin

I'm using ASP.NET plugin for reCAPTCHA in my ASP.NET MVC application. Recaptcha assembly version is 1.0.4.0. Is there a way to set language to be used for RecaptchaControl?
var captchaControl = new Recaptcha.RecaptchaControl
{
ID = "recaptcha",
Theme = "blackglass",
PublicKey = "public_key",
PrivateKey = "private_key"
};
This feature was not supported in v1.0.4.0. Please download the latest version and try again.
http://code.google.com/p/recaptcha/downloads/detail?name=recaptcha-dotnet-1.0.5.0-binary.zip
with the help of this article here is how I've done it. the key is editing the generated html at the end; replacing "RecaptchaOptions = {" with "RecaptchaOptions = { lang : 'supported_language_code',"
public static string GenerateCaptcha(this HtmlHelper helper)
{
var captchaControl = new Recaptcha.RecaptchaControl
{
ID = "recaptcha",
Theme = "clean",
PublicKey = "public_key_here",
PrivateKey = "private_key_here"
};
var htmlWriter = new HtmlTextWriter(new StringWriter());
captchaControl.RenderControl(htmlWriter);
var html = htmlWriter.InnerWriter.ToString();
html = html.Replace("RecaptchaOptions = {", "RecaptchaOptions = { lang : 'tr', ");
return html;
}
EDIT: A cleaner solution is given here. (System.Web.Helpers)

Resources