UPDATE: I still haven't solved it, my my current work around is to not do a desktop client. I've switched back to a web app for now, and everything is working again. I don't know, I'm stumped.
I've been able to get my Twitter web app working just fine, but I've recently decided to add Tweeting functionality from a Windows Form, but I'm having no luck sending tweets. No errors are thrown or anything. Mind looking over my code?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TweetSharp;
namespace TwitterAdvirtiser
{
public partial class Form1 : Form
{
private string cKey = "xxx";
private string cSecret = "xxx";
private string oToken = "xxx";
private string aToken = "xxx";
public Form1()
{
InitializeComponent();
OnStart();
}
private void OnStart()
{
//Authenticate with Twitter
TwitterService service = new TwitterService(cKey, cSecret);
service.AuthenticateWith(oToken, aToken);
service.SendTweet("testing");
}
}
}
It seems like I'm authenticating just fine, I can walk through debug mode and see all my details in the TwitterUser structure, and yet my tweets never show up on my feed. Whats up?
By the way, I'm using Visual Studios 2010, and .NET 4.0. I have verified that the oToken and aToken strings have my developer tokens.
As far as I can see you're only authenticating using the Consumer Key, Consumer Secret, Token Key and Token Secret. You also need to include the verifier pin with the signature base.
Related
I am trying to use Mailjet to send messages via email, but why is the word version not recognized in it? I downloaded the mailgate package
I'm practicing programming using the asp.net core5.0 framework.
Are there other distinct ways to send messages via e-mail?
Any advice from you?
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.UI.Services;
using Newtonsoft.Json.Linq; ][1]
If you have Version = ApiVersion.V3_1, as part of your sample code, comment it out and add the appropriate BaseAdress line in the example below:
MailjetClient client = new MailjetClient("xxx-example-xxx", "xxx-example-xxx")
{
BaseAdress = "https://api.mailjet.com",
//BaseAdress = "https://api.us.mailjet.com",
//Version = ApiVersion.V3_1,
};
Preface:
This is a part of my personal project of building a control GUI for several communication devices - using WinForms unfortunately.
The part of code running into trouble is rested inside the Constructor of a Form.
Additional NuGet packages installed are: Newtonsoft.Json, RestSharp, SpecFlow and SpecFlow.Assist.Dynamic.
LoginForm and SeatsInfo are two basic classes created only to store and organize my data, they have no additional coding besides properties declartions.
Execution code:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CONTROL_UI
{
public partial class RunningConfig : Form
{
public RunningConfig()
{
InitializeComponent();
var client = new RestClient("CLIENT_URL");
var loginRequest = new RestRequest("api/login", Method.POST);
loginRequest.RequestFormat = DataFormat.Json;
loginRequest.AddHeader("Content-type", "application/json");
loginRequest.AddJsonBody(new LoginForm() { username = "admin", password = "", #override = true });
var loginRespone = client.Execute(loginRequest);
JObject sessionInfo = JObject.Parse(loginRespone.Content);
var sessionID = sessionInfo["sid"];
var seatAvailRequest = new RestRequest("api/seats", Method.GET);
seatAvailRequest.AddHeader("sid", sessionID.ToString());
seatAvailRequest.AddHeader("Cookie", "sid = " + sessionID.ToString());
var seatResponse = client.Execute(seatAvailRequest);
List<SeatsInfo> seatsInfo = JsonConvert.DeserializeObject<List<SeatsInfo>>(seatResponse.Content);
//Further Implementation
}
}
}
Expected packet view in WireShark:
Actual packet view in WireShark:
sids are generated each time I successfully authorized to connect to the device, so they obviously differ.
The screenshot of my expected view is taken from the exact same block of codes in a plain console app. Everything works fine there. All the NuGet packages installed on the two programmes are of the same version, I even tried running them side-by-side but it did not help.
Debugging screenshots showed that the Parameters did, in fact, contain the Cookie header:
The header just did not go through for some reason. Would love to hear some thoughts in regards to this issue, many thanks in advance!
Current solution, just add another AddCookie() method:
seatAvailRequest.AddHeader("sid", sessionID.ToString());
seatAvailRequest.AddHeader("Cookie","sid = " + sessionID.ToString());
seatAvailRequest.AddCookie("sid", sessionID.ToString());
This somehow does not work with just AddCookie() or AddHeader(), so for now they are both going in. Hope this helps someone, and thank yall for reading!
So, in recap I was lacking the Cookie Header in the API call thus making the call being unsuccessful (the device did not authorized it).
After messing around with the AddCookie() method, particularly:
seatAvailRequest.AddCookie("sid", sessionID.ToString());
The device gave me a different error - 404 Not Found, before was 401 Unauthorized:
Finally my dumb mind resorted using both the AddCookie() along with AddHeader() and voilà:
It works! Only after 5 hours of painful debugging and mind-numbing searches. Although the new packet is a bit larger, but I do not have to worry about that for now, or in the future realistically speaking.
Thanks you all for just following along, still open for suggestions and improvements!
I'm trying to add a feature in my C# app that looks up the email address associated with the Windows login, but I can not find anything on this!
The closest thing I found was it being listed in the Registry # "HKEY_CURRENT_USER\Software\Microsoft\IdentityCRL" for one person, but not on any of my machines.
I've also tried "System.DirectoryServices.AccountManagement.UserPrincipal.Current.EmailAddress" but it returns nothing.
Has anyone ever had to look this up programmatically before? If so, any advice?
Interesting question. It got me looking around. This is what I got so far from a C# WinApp project. Under a Microsoft login account, I got it to display the "UserName" property that had my associated email address. Under a regular local account, it returned nothing. Run with it. Good luck.
using System;
using System.Linq.Expressions;
using System.Windows;
using System.Windows.Forms;
namespace WindowsAuthenticationProbing
{
class Program
{
static void Main(string[] args)
{
//interesting to look at, but does not reveal the associated Windows login email
var myIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
var userTask = Windows.System.User.FindAllAsync().AsTask();
userTask.Wait();
var users = userTask.Result;
foreach (var user in users)
{
var propTask = user.GetPropertiesAsync(new[] { "UserName" }).AsTask();
propTask.Wait();
var props = propTask.Result;
foreach(var x in props)
{
MessageBox.Show($"User is {x.Value}");
}
}
}
}
}
I am currently trying to use Google Cloud Vision API on C#.
After downloading JSON file for google cloud authentication, I have set the system environment variable as the path of the JSON file and compiled my code. It was all good.
However, when I created DLL with the source it seems like the DLL could not get the Google Application Credentials value from the system environment variable.
So that I studied some of the Google Credential Authentication documents to put a code at the very first line of C# code to deliver my JSON file path to recognize my vision api calls.
However, the code is not working to properly authenticating my JSON file to call Google Vision API.
Please enlighten me with your knowledge! Thanks.
Here is my code.
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Util.Store;
using Google.Cloud.Vision.V1;
using Image = Google.Cloud.Vision.V1.Image;
using Grpc.Core;
using Grpc.Auth;
namespace dotNetFramework461_Console
{
class Program
{
public string GVA_API()
{
string jsonPath = "D:\\blablablah\\abcdefghijk.json";
string imgPath = "C:\\Users\\blablablah\\image.jpg";
var stream = new FileStream(jsonPath, FileMode.Open, FileAccess.Read);
var credential = GoogleCredential.FromStream(stream).CreateScoped(ImageAnnotatorClient.DefaultScopes);
var channel = new Grpc.Core.Channel(ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());
var client = ImageAnnotatorClient.Create(channel);
var image = Image.FromFile(imgPath);
TextAnnotation text = client.DetectDocumentText(image);
return text.Text;
}
}
}
I`m relatively new to programming and I´m completely new to Stack overflow, so please be patient with me! Currently I work on a ASP.NET MVC project including the Ebay finding API.
The goal i want to accomplish is to create a Website on which you can search for different articles on Ebay and being able to use certain filters using the Ebay finding API. This is a training projekt for me, as the C# part of the whole thing is a good practice in my opinion. Unfortunately I´m stuck with the whole API connection to ebay part and havent done any C# programming myself.
Frankly i have no idea what im doing and I hope some of you may have an idea or some tips for me. I know I might be vague and I´m sorry, but i´m just at the beginning of programming.
What have i done so far?
I already registered on the ebay developers program and I already have my App ID, the Dev IDm the Cert ID and a Token.
Important: I currently only work with the sandbox!
I found a piece of code online which I´m using, but now im stuck. Obisously i filled in the IDs and the token but deleted it for this post. In the "Index" class at the end of my piece of code I entered the ID of a random Ebay article for testing purposes. When i debug I get this Exception:
"eBay.Service.Core.Sdk.ApiException: 'This item cannot be accessed because the listing has been deleted, is a Half.com listing, or you are not the seller."
I would really appreciate if someone can show me how to do it correctly or push me in the right direction. I have to admit that i find the whole Ebay API documentation etc. to be very confusing and I dind´t find any advice on how to start. I take any advice you guys can give me!
Here is the code I found and used so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Windows.Forms;
using System.Resources;
using eBay.Service.Call;
using eBay.Service.Core.Sdk;
using eBay.Service.Core.Soap;
namespace Ebay_API_Neu.Controllers
{
public class HomeController : Controller
{
public GetItemCall getItemDataFromEbay(String itemId)
{
ApiContext oContext = new ApiContext();
oContext.ApiCredential.ApiAccount.Developer = "//dev ID"; // use your dev ID
oContext.ApiCredential.ApiAccount.Application = "//App ID"; // use your app ID
oContext.ApiCredential.ApiAccount.Certificate = "//cert ID"; // use your cert ID
oContext.ApiCredential.eBayToken = "//Token"; //set the AuthToken
oContext.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi";
//set the Site of the Context
oContext.Site = eBay.Service.Core.Soap.SiteCodeType.Germany;
//the WSDL Version used for this SDK build
oContext.Version = "735";
//very important, let's setup the logging
ApiLogManager oLogManager = new ApiLogManager();
oLogManager.ApiLoggerList.Add(new eBay.Service.Util.FileLogger("GetItem.log", true, true, true));
oLogManager.EnableLogging = true;
oContext.ApiLogManager = oLogManager;
GetItemCall oGetItemCall = new GetItemCall(oContext);
//' set the Version used in the call
oGetItemCall.Version = oContext.Version;
//' set the Site of the call
oGetItemCall.Site = oContext.Site;
//' enable the compression feature
oGetItemCall.EnableCompression = true;
oGetItemCall.DetailLevelList.Add(eBay.Service.Core.Soap.DetailLevelCodeType.ReturnAll);
oGetItemCall.ItemID = itemId;
try
{
oGetItemCall.GetItem(oGetItemCall.ItemID);
}
catch (Exception E)
{
Console.Write(E.ToString());
oGetItemCall.GetItem(itemId);
}
GC.Collect();
return oGetItemCall;
}
public ActionResult Index()
{
getItemDataFromEbay("173354849991");
return View();
}
From the error you are getting I would guess that you are trying to get information regarding a "random listing" you have not entered yourself on the eBay sandbox. In order to use GetItem the listing you are retrieving has to have been created using your sandbox user id.
Take a look at the below link to API doc for GetItem() - specifically the requirements for "Testing GetItem". If you think I might be correct then try creating a listing in the sandbox using either the Web Interface or eBay API AddItem() before retrieving it with GetItem().
https://developer.ebay.com/devzone/xml/docs/reference/ebay/getitem.html