-2

I'm trying to get comments from linkedin by using API

But I'm getting an error, in few places

Can anyone help me to resolve an error?

I've written this code

 protected void Page_Load(object sender, EventArgs e)
    {
        var request = new RestRequest { Path = "posts?order=recency&category=discussion" };

        var credentials = new OAuthCredentials

        {
            ConsumerKey = "kmkzt9cqml1s", 
            ConsumerSecret = "hNiwIrZWGSMykoD2", 
        };


        var client = new RestClient()
        {
            Authority = "http://api.linkedin.com/v1/groups/345455/",
            Credentials = credentials//Here I'm getting an error
        };

        //Here how to create Request method
        var MyInfo = client.Request(request);

        String content = MyInfo.Content;

        string strURL = "http://api.linkedin.com/";
        System.Net.HttpWebRequest objWebRequest = null;
        System.Net.HttpWebResponse objWebResponse = null;
        System.IO.StreamReader streamReader = null;
        string strHTML = null;

        System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; };

        objWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strURL);
        objWebRequest.PreAuthenticate = true;
        objWebRequest.Method = "GET";

        objWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;

        objWebResponse = (System.Net.HttpWebResponse)objWebRequest.GetResponse();

        streamReader = new System.IO.StreamReader(objWebResponse.GetResponseStream());

        strHTML = streamReader.ReadToEnd();


        streamReader.Close();
        objWebResponse.Close();
        objWebRequest.Abort();

        Response.ContentType = "text/xml";
        Response.Write(strHTML);
        Response.End();

    }  

RestClient.cs

 public class RestClient
  {
    private string _consumerKey = "";
    private string _consumerSecret = "";

    #region Properties
    public string Authority
    {
        get
        {
            return _consumerKey;
        }
        set { _consumerKey = value; }
    }

    //Here giving string
    public string Credentials
    {
        get
        {
            return _consumerSecret;
        }
        set { _consumerSecret = value; }
    }
    #endregion
}

How to create Request() Method? Any ideas? Thanks in advance.

user2500094
  • 1,033
  • 6
  • 23
  • 42
  • Exception in topic caused by invalid implicit cast. Check line which compiler point you and resolve issue. Code you provided is too common. – Tommi Jun 19 '13 at 12:48
  • Double click the error and you wil land in the line where the error is caused. Hover over the left and right side of the assignment to see that you are using incompatible datatypes. –  Jun 19 '13 at 12:54

4 Answers4

0

Your RestClient has a Credentials property that is a string; Your code is trying to put something that isn't a string (in your case, an OAuthCredentials) into it. This is not a allowable, as there is no implicit conversion between the two types.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
0

In RestClient, Credentials is string, but you are affecting a OAuthCredentials to it ( Credentials = credentials ).

Try changing the type of the property (and the backing field) Credentials to OAuthCredentials.

Ahmed KRAIEM
  • 10,267
  • 4
  • 30
  • 33
0

Credentials is not of type OAuthCredentials, it's of type string, so you can't assign it with your credentials variable, which is of type OAuthCredentials. Since the RestClient class references a variable named _consumerSecret, and such and so, let's assume you actually want to do this:

Authority = credentials.ConsumerKey;
Credentials = credentials.ConsumerSecret;
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
0

As the error says, you're trying to assign a OAuthCredentials object (credentials) into a string typed attribute of the RestClient object : Credentials.

You have to either do Credentials = credentials.toString() or change the RestClient class.

C4stor
  • 8,355
  • 6
  • 29
  • 47