Results 1 to 4 of 4
  1. #1
    Newbie
    Join Date
    May 8th, 2010
    Posts
    8
    CJ Rest API: Authentication in c#
    It seems odd that CJ doesn't provide any .net support.
    Anyway, I can't get this to work. Does anyone have any sample code they could share?


    string FetchURL = "https://linksearch.api.cj.com/v2/link-search?website-id=MYWEBSITE_ID&link-type=Text Link";
    WebRequest myReq = WebRequest.Create(FetchURL);
    myReq.Headers.Add("authorization", "MY GIANT TOKEN");
    HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();


    I keep getting "The remote server returned an error: (401) Unauthorized."
    Anyone else have experience with this?

    I got my token to work using the Modify Headers firefox addon, so I know it's not that...

  2. #2
    ABW Ambassador Georgie Peri's Avatar
    Join Date
    January 18th, 2005
    Location
    Norwalk, CT
    Posts
    846
    Greetings ..

    Heres what I use .. sorry I'm not that great @ coding .. nor C#

    Maybe you can figure something out with my example ..

    Code:
    %
    
    Function HTMLDecode(sText)
        Dim I
        sText = Replace(sText, """, Chr(34))
        sText = Replace(sText, "<"  , Chr(60))
        sText = Replace(sText, ">"  , Chr(62))
        sText = Replace(sText, "&" , Chr(38))
        sText = Replace(sText, " ", Chr(32))
        For I = 1 to 255
            sText = Replace(sText, "&#" & I & ";", Chr(I))
        Next
        HTMLDecode = sText
    End Function
    
    filename = Request.QueryString("filename")
    midnum = Request.QueryString("midnum")
    
    dim oFs, sXML, oFile
    Set oFs = Server.CreateObject("Scripting.FileSystemObject")
    
    SUB makeFeed(url)
    
      Response.Buffer = True
      Dim objXMLHTTP, xml
    
      Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    
      xml.Open "GET", url, False
    
      xml.setRequestHeader "authorization", "***PUT LONG Number TOken HERE****"
    	
      ' Actually Sends the request and returns the data:
      xml.Send
    
    sXml = xml.responseText
    
    'sXml = Replace(sXml,"&","&") 
    'sXml = Replace(sXml,"'","'") 
    
    'sXml = Replace(sXml,"<","<") 
    'sXml = Replace(sXml,">",">") 
    sXml = Replace(sXml,"UTF-8","iso-8859-1") 
    
    
    Set oFile = oFs.OpenTextFile(Server.MapPath("/***PUTFOLDERHERE***/" & filename), 2, true)
    oFile.Write sXml
    oFile.Close
    
    Set oFile = Nothing
    Set oFs = Nothing
    Set xml = Nothing
    
    end sub
    
    makeFeed("https://linksearch.api.cj.com/v2/link-search?website-id=***PID***&advertiser-ids="& midnum &"&promotion-type=coupon,sale/discount,free+shipping&link-type=Text+Link&page-number=1&records-per-page=100")
    
    %>
    Thats what I tested out for grabbing data via ASP...

    I dont use this due to a number of issues with expired offers and other things ...

    Hope this gives you a clue in your issue...

    try the BOLD'ed Line as your FetchURL, make sure to have a MID in there thou ..
    OpA! Giasou Ti kanies!

  3. #3
    Member esnagel's Avatar
    Join Date
    January 1st, 2008
    Location
    Buffalo, NY
    Posts
    88
    Quote Originally Posted by kevinmcc View Post
    string FetchURL = "https://linksearch.api.cj.com/v2/link-search?website-id=MYWEBSITE_ID&link-type=Text Link";
    WebRequest myReq = WebRequest.Create(FetchURL);
    myReq.Headers.Add("authorization", "MY GIANT TOKEN");
    HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
    Does the "A" in authorization have to be capitalized? That's how I have it in mine... not sure if headers are case-sensitive

  4. #4
    Newbie
    Join Date
    May 8th, 2010
    Posts
    8
    Thanks to you both!
    Lowercase "a" it was!

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Two-step/factor authentication and now locked out...
    By GuardianAngel in forum ShareASale - SAS
    Replies: 3
    Last Post: July 19th, 2014, 11:05 PM
  2. Need help with php & user authentication form
    By teezone in forum Programming / Datafeeds / Tools
    Replies: 5
    Last Post: January 7th, 2013, 01:19 PM
  3. For Loxly - ok the rest of ya can look, too. :)
    By purplebear in forum Virtual Family and Off-Topic
    Replies: 12
    Last Post: April 4th, 2009, 11:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •