I'm trying to authenticate an api call using oauth
I have the consumer keys and secrets, so was hoping to just use DotNetOpenOAuth and hey presto, but after a frustrating day and a sore head, I cant figure it out..
I've got the following sample - that works in python using the python-oauth2 library - anyone have any experience / ideas about how to translate this? Everything I can find is dealing with user based callback urls - but here i just have a more complicated version of the good old user/pwd (know its a little more complicated - but hopefully get my gist!)
consumer=oauth.Consumer(key='CONSUMERKEY', secret='ITSASECRET')
# Your unique key:
token= oauth.Token('CLIENTKEY','ITSASECRET')
# The client object which combines both consumer and token:
client = oauth.Client(consumer, token=token)
# To figure out what reporting options you have, first run the following:
response_headers, response_content = client.request(url)
# The below will display the reporting options you have available:
print cjs
on.dumps(response_content)
EDIT: updated to reflect that this is OAuth 1.0, not 2
Related
Morning all,
I've not posted on SO for quite some time, but I need to ask the question, I’ve spent a day and a half trying to get this to work - it’s super frustrating considering I managed to implement v2 with posting a tweet in 2 - 3 hours but because I need the media endpoint (does not exist in v2), I rebuilt my flow into v1 to upload media.
Ok, so my app allows the user to authenticate with twitter and tweet/upload media. I’m using (I think) the 3-legged oauth flow.
Currently, the flow is :
https://api.twitter.com/oauth/request_token - 200 status code and I
confirm the callback URL
I use the access token from step 1, and then call/redirect
https://api.twitter.com/oauth/authorize?oauth_token={accessToken}
this obviously redirects to my endpoint.
I extract the oauthToken and oauthVerifier and call:
https://api.twitter.com/oauth/access_token, this returns an
oauthToken and oauthTokenSecret, I store the values.
All of the above conforms to what is in the docs, but when I use the stored values from step 3 to post a tweet I get unauthorized.
The signing logic works because it’s what’s used in “Request access token” - with a couple of changes.
I'm learning more towards a flow issue due to trying various nuget packages(tweetinvi in particular) and I get exceptions in those too.
Any help is greatly appreciated.
Not really an answer per-se, but rather notable actions.
At this point in time, you cannot upload media with V2 of the API, whilst you can integrate quite quickly and send a tweet, it's almost pointless without media.
So, you'll need to build/integrate with V1.
The unknowns and curve balls:
The most important! V1 requires elevated access! Which you'll need to
apply for, not all get accepted! but V2 just integrate and tweet with
no elevated access - very strange.
Always ensure to read the resp correctly, and try few times in code, postman,
fiddler etc. Whilst the resp contains a collection of errors object,
you'll never get a collection of errors.
If you're not using any sort of package/library, pay close attention
to crafting the request signature - it's a pain.
Maybe title is not that clear but..
I have created a POST query that works in Postman using OAuth 1.0 authentication.
Mu calls are made to url:
https://lo.enghist.liveperson.net/abc/api/def/1234567/ghi/search
How does postman know all other urls - to request token url etc.
I’m trying to rewrite it in a custom C# app but have no idea how to track what happens when I click send - if I go to Developer Console I only see the final request with final params that were obtained somewhere?
Is it always sth default like:
https://lo.enghist.liveperson.net/oauth/request_token
Answering myself:
I didn't correctly understand OAuth 1.0. I first thought that there is a different URL that we make calls to receive the token which we then use to make the final call. This is not the case, we create our token using secrets, nonce (random string) and few other rules, then it's all hashed and sent to WebService which does the same and compares both values.
Postman now provides you with code - below the button "Send" there is a link "Code" which gives you so many languages and one of them is C# using RestSharp.
Regarding above, it sadly shows a semi working solution - quite a lot of logic is skipped and all the values are precalculated so I was thinking I need to calculate them myself even if RestSharp can do that for you, please check my final working code here:
https://stackoverflow.com/a/64819771/1619684
I am trying to display YouTube analytics data in a .Net application (Asp.net MVC 4 to be specific) using the google api .net client
The only sample I could find for this was a JavaScript sample located here for the most parts I was able to recreate the code in .Net, The only problem is that I don't seem to be able to find the counterpart for this lines of code which returns a list of Channels for the authenticated user:
var request = gapi.client.youtube.channels.list({
// "mine: true" indicates that you want to retrieve the authenticated user's channel.
mine: true,
part: 'id,contentDetails'
});
which should be then used here in my code:
var request = youtubeAnalyiticsService.Reports.Query(
"channel=="+ channelId, fromDate, toDate,
"views,likes,dislikes" // metrics to include in report
);
What I currently do to get it to work is to copy and paste the channel Id here and therefore "hard-code" it which is not practical in this my case and used only for testing purposes.
Hopefully I'm wrong but after searching for hours I think that the .Net API might be missing this part, can anyone confirm this? and if true are there any alternatives for doing this in the .net application?
I also guess that there might be a straightforward way to just use that part of the JavaScript code in the .net application but I'm not sure how!
Any help, hint or clarification would be much appreciated :)
This should work, assuming you've already got OAuth 2 setup and youtube is a YouTubeService object that's been properly authorized:
ChannelsResource.ListRequest channelsListRequest = youtube.Channels.List("id");
channelsListRequest.Mine = true;
ChannelListResponse channelsListResponse = channelsListRequest.Fetch();
string channelId = channelsListResponse.Items[0].Id;
Hi does anyone know how to use the streaming API for C#? Therefore, whenever there is a new tweet in my account, it will be reflected in my program.
So far the only reliable wrapper I've found for this in .Net land is TweetInvi. Try to ignore that the web site looks like it was designed by a hyperactive 10-year old (thanks MS 'metro' team), the actual library is very well designed and rock solid.
Assuming of course you have the relevant access tokens (if not see http://dev.twitter.com), an example of how easy it is to have up and running:
TwitterCredentials.SetCredentials(userToken,userTokenPrivate,apiKey,apiKeyPrivate);
_userStream = Stream.CreateUserStream();
_userStream.TweetCreatedByFriend += (sender,args) => Console.WriteLine(args.Tweet.Text);
_userStream.Start();
This will write the body of tweets to your console output, and it updates even faster than leaving the actual Twitter web site open. There are other events exposed for when a tweet is favourited, retweeted, when you have a new follower etc.
I can vouch for this library as being reliable - I am using it for my CovertTweeter project and have had absolutely no issues with it. In fact accessing the streaming API through TweetInvi has been even easier than the many brick walls I was left hitting when using REST wrappers like Linq2Twitter and TweetSharp.
Have a look at this post:
Streaming with New .NET HttpClient and HttpCompletionOption.ResponseHeadersRead
You don't have the complete implementation there but you will get the idea.
Here is a sample which "Reads data from the Twitter Streaming API and adds it to MSMQ. A second process (included) reads from the queue, parses the json message, and updates a data store."
https://github.com/swhitley/TwitterStreamClient
You can change the above problem to generate an event when it updates the data store. In your program you can subscribe this event to do whatever you want.
If you are looking for OAuth based sample then please use "AuthPack" which Provides .NET oAuth for Twitter, Facebook, LinkedIn, and Google:
https://github.com/swhitley/AuthPack/tree/master/AuthPack
I have found a good sample code that uses streaming API, here Twitterizer.
As of August 15, Amazon made it compulsory to sign all requests made to their Product Advertising API. I thought I had got everything working just fine but when the 15th finally came around, my web application stopped working and pretty much ever since I have been trying to find out how to sign the SOAP requests.
Amazon has an outdated sample code for signing requests that doesn't appear to work here
Basically, I need to know how to add a signature to the my requests using the most current C# SOAP API and .NET 3.5.
I hope I have given enough details, if I haven't please feel free to ask me to elaborate.
Thank You
The_Lorax
UPDATE:
I am using MVC and need to know how to add the Signature to the the ItemLookup or AWSECommerceService object. Is there an attribute that contains the signature value? How does it get attached to the request?
On this page, they say that I must include the Signature and TimeStamp parameters but the intellisense does now show any such attributes.
Check out http://flyingpies.wordpress.com/2009/08/01/17/. It has a walkthrough and a sample visual studio solution using C#, SOAP, WCF on .NET 3.5.
This library automatic sign the requests (Install-Package Nager.AmazonProductAdvertising)
https://www.nuget.org/packages/Nager.AmazonProductAdvertising/
Example:
var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US);
var result = await client.SearchItemsAsync("canon eos");