Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9131187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:06:11+00:00 2026-06-17T08:06:11+00:00

I’m trying to write a basic program using DotNetOpenAuth to search for people on

  • 0

I’m trying to write a basic program using DotNetOpenAuth to search for people on behalf of a user. Just a simple program to try to learn about OAuth. Right now I’m stuck trying to authorize, but when I try to do so I get a HTTP 400 status code from linkedIn.

I’ve tried using both DesktopConsumers and WebConsumers, both of which fail in the same way. I know that the specific function that is caused the exceptioin is the call to RequestUserAuthorization on line 34 and I’ve tried using both empty dictionaries and nulls as inputs for it, but nothing’s happened.

I’m using two classes for the program a TestLinkedIn.cs class containing the main and a LinkedInTokenManager.cs class which is a pretty straightforward implementation of IConsumerTokenManager.

Here’s the code for TestLinkedIn.cs.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth.Messages;
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;

namespace Project
{
    class TestLinkedIn
    {
        #region Variables
        private static string APIKey = "APIKey";
        private static string APISecret = "APISecret";
        private static string OAuthToken = "OAuthToken";
        private static string OAuthSecret = "OAuthSecret";
        #endregion

        static void Main(string[] args)
        {
            ServiceProviderDescription linkedIn = LinkedInDescription();
            LinkedInTokenManager tokenManager = new LinkedInTokenManager(OAuthToken, OAuthSecret);//APIKey,APISecret);//
            DesktopConsumer web = new DesktopConsumer(linkedIn,tokenManager); 
            string requestToken = "";
            Uri authUrl = new Uri("https://steve.com");// ("https://api.linkedin.com/uas/oauth/requestToken");//"http" + "://" + "api.linkedin.com" + "/Home/OAuthCallBack");
            Dictionary<string, string> empty = new Dictionary<string, string>();
            try{
                //UserAuthorizationRequest request = web.PrepareRequestUserAuthorization(null, null, null, out requestToken);//null, null, null);//authUrl, null, null);
                //UserAuthorizationRequest request =web.Channel.Request(new AccessProtectedResourceRequest());
                //web.Channel.Send(request);
                authUrl = web.RequestUserAuthorization(empty, empty, out requestToken);
                Console.WriteLine(requestToken);
                Console.ReadKey();
            }
            catch (ProtocolException e)
            {
                Console.Write(e.StackTrace);
                Console.WriteLine("Error detected");
                //Console.ReadKey();
            }
        }

        private static ServiceProviderDescription LinkedInDescription(){
            ServiceProviderDescription linkedIn = new ServiceProviderDescription();
            linkedIn.AccessTokenEndpoint = new DotNetOpenAuth.Messaging.MessageReceivingEndpoint
                ("https://api.linkedin.com/uas/oauth/accessToken", DotNetOpenAuth.Messaging.HttpDeliveryMethods.PostRequest);
            linkedIn.RequestTokenEndpoint = new DotNetOpenAuth.Messaging.MessageReceivingEndpoint
                ("https://api.linkedin.com/uas/oauth/requestToken",DotNetOpenAuth.Messaging.HttpDeliveryMethods.PostRequest);
            linkedIn.UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://www.linkedin.com/uas/oauth/authorize",
                HttpDeliveryMethods.PostRequest);
            linkedIn.TamperProtectionElements =new ITamperProtectionChannelBindingElement[]
                {new HmacSha1SigningBindingElement()};
            linkedIn.ProtocolVersion=ProtocolVersion.V10a;
            return linkedIn;
        }
    }
}

and here’s the code for LinkedInTokenManager

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;

namespace Project
{
    class LinkedInTokenManager : IConsumerTokenManager
    {
        private Dictionary<string, string> tokens = new Dictionary<string, string>();
        private string consumerKey;
        private string consumerSecret;

    public LinkedInTokenManager(string Key, string Secret)
    {
        consumerKey = Key;
        consumerSecret = Secret;
    }
    public string ConsumerKey
    {
        get { return consumerKey; }
    }

    public string ConsumerSecret
    {
        get { return consumerSecret; }
    }

    public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret)
    {
        tokens.Remove(requestToken);
        tokens[accessToken] = accessTokenSecret;
    }

    public string GetTokenSecret(string token)
    {
        try
        {
            return tokens[token];
        }
        catch (KeyNotFoundException k)
        {
            return null;
        }
    }

    public TokenType GetTokenType(string token)
    {
        throw new NotImplementedException();
    }

    public void StoreNewRequestToken(UnauthorizedTokenRequest request, ITokenSecretContainingMessage response)
    {
        tokens[response.Token] = response.TokenSecret;
    }
  }
}

This is the stuff I’m posting to the server.

oauth_callback=oob&oauth_consumer_key=6415f7ed-d618-422a-b090-73f3056653d7&oauth_nonce=nGQjFcC1&oauth_signature_method=HMAC-SHA1&oauth_signature=XmUBfGVGDoBZDOC%2Bjp4Fj68MPGI%3D&oauth_version=1.0&oauth_timestamp=1357136418

and here is the stack trace from the error message.

at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options)
   at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request)
       at DotNetOpenAuth.Messaging.Channel.GetDirectResponse(HttpWebRequest webRequest)
       at DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request)
       at DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage)
       at DotNetOpenAuth.Messaging.Channel.Request[TResponse](IDirectedProtocolMessage requestMessage)
       at DotNetOpenAuth.OAuth.ConsumerBase.PrepareRequestUserAuthorization(Uri callback, IDictionary`2 requestParameters, IDictionary`2 redirectParameters, String& requestToken)
       at DotNetOpenAuth.OAuth.DesktopConsumer.RequestUserAuthorization(IDictionary`2 requestParameters, IDictionary`2 redirectParameters, String& requestToken)
       at APIphanySalesProject.TestLinkedIn.Main(String[] args) in c:\Users\Admin\Documents\Visual Studio 2012\Projects\Project\Project\TestLinkedIn.cs:line 34

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:06:12+00:00Added an answer on June 17, 2026 at 8:06 am

    If you’re encountering the same problem as I was, try checking your computer’s time settings. Both the time and time zone need to be correct for it to generate correct timestamps, which is what was wrong with my program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.