My Ebay Plugin
Posted: May 27th, 2006, 4:16 pm
maby some plugin for e-bay, for tracking auctions?
I know this is an old one, but this could be a good plugin and could work well using the webservices dll and the ebay developer kit.he3r0 wrote:maby some plugin for e-bay, for tracking auctions?
Code: Select all
Imports System.Net ' for the HttpWebRequest
Imports System.Text ' for the character encoding
Imports System.IO ' for Stream(s)
Imports System.Xml ' for XmlDocument Processing
'Imports System.Configuration ' for AppSettings (keys, tokens, etc)
Imports System.Reflection ' for Embedded XML File
Imports System.Web
'' Retrieve the information for an Auction-Type listed item
'' that is active or has ended within the past 90 days.
Public Class LCDSmartie
Public Function function1(ByVal param1 As String, ByVal param2 As String) As String
'checkerror("check_01")
'Get the Keys from App.Config file
'Dim devID As String = ConfigurationSettings.AppSettings("DevID")
Dim appID As String = "************************************"
' Dim certID As String = ConfigurationSettings.AppSettings("CertID")
'Get the Server to use (Sandbox or Production)
Dim serverUrl As String = "http://open.api.ebay.com/shopping?"
'Get the User Token to Use
'Dim userToken As String = ConfigurationSettings.AppSettings("UserToken")
'SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....
'SiteID Indicates the eBay site to associate the call with
Dim siteID As Integer = 0
'checkerror("check_02")
'Item Id - the ID that uniquely identifies an item
'Console.Write("Enter Item ID: ")
Dim itemID As String = param1
'Load the XML Document to Use for this Request
Dim xmlDoc As XmlDocument = New XmlDocument
'Get XML Document from Embedded Resources
xmlDoc.Load(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("GetSingleItemRequest.xml"))
'checkerror("check_03")
'Return "done"
'Set the various node values
'xmlDoc("GetItemRequest")("RequesterCredentials")("eBayAuthToken").InnerText = userToken
xmlDoc("GetSingleItemRequest")("ItemID").InnerText = itemID.ToString()
'Get XML into a string for use in encoding
Dim xmlText As String = xmlDoc.InnerXml
'checkerror("check_04")
'Return "done"
'Put the data into a UTF8 encoded byte array
Dim encoding As UTF8Encoding = New UTF8Encoding
Dim dataLen As Integer = encoding.GetByteCount(xmlText)
Dim utf8Bytes() As Byte = New Byte(dataLen - 1) {}
encoding.UTF8.GetBytes(xmlText, 0, xmlText.Length, utf8Bytes, 0)
'Return "done"
'checkerror("check_05")
'Create a new HttpWebRequest object for the ServerUrl
Dim request As HttpWebRequest = CType(WebRequest.Create(serverUrl), HttpWebRequest)
'Set Request Method (POST) and Content Type (text/xml)
request.Method = "POST"
request.ContentType = "text/xml"
request.ContentLength = utf8Bytes.Length
'checkerror("check_06")
'Add the Keys to the HTTP Headers
'request.Headers.Add("X-EBAY-API-DEV-NAME: " + devID)
request.Headers.Add("X-EBAY-API-APP-ID: " + appID)
'request.Headers.Add("X-EBAY-API-CERT-NAME: " + certID)
'Add Compatability Level to HTTP Headers
'Regulates versioning of the XML interface for the API
request.Headers.Add("X-EBAY-API-VERSION: 543")
'Add function name, SiteID and Detail Level to HTTP Headers
request.Headers.Add("X-EBAY-API-CALL-NAME: GetSingleItem")
request.Headers.Add("X-EBAY-API-SITEID: " + siteID.ToString())
'Time out = 15 seconds, set to -1 for no timeout.
'If times-out - throws a WebException with the
'Status property set to WebExceptionStatus.Timeout.
request.Timeout = 15000
'checkerror("check_07")
Dim str As Stream = Nothing
Try
'Set the request Stream
str = request.GetRequestStream()
'Write the equest to the Request Steam
str.Write(utf8Bytes, 0, utf8Bytes.Length)
str.Close()
'Get response into stream
Dim resp As WebResponse = request.GetResponse()
str = resp.GetResponseStream()
Catch wEx As WebException
'Error has occured whilst requesting
'Display error message and exit.
If wEx.Status = WebExceptionStatus.Timeout Then
Console.WriteLine("Request Timed-Out.")
Return "error_x"
Else
Console.WriteLine(wEx.Message)
End If
Console.WriteLine("Press Enter to Continue...")
Console.ReadLine()
'Return
End Try
'checkerror("check_08")
' Get Response into String
Dim sr As StreamReader = New StreamReader(str)
xmlDoc.LoadXml(sr.ReadToEnd())
sr.Close()
str.Close()
Dim root As XmlNode = xmlDoc("GetSingleItemResponse")
Dim iteminfo As String
'There have been Errors
If Not root("Errors") Is Nothing Then
Dim errorCode As String = root("Errors")("ErrorCode").InnerText
Dim errorShort As String = root("Errors")("ShortMessage").InnerText
Dim errorLong As String = ""
If Not root("Errors")("LongMessage") Is Nothing Then
errorLong = root("Errors")("LongMessage").InnerText
End If
'Output the error message
Console.WriteLine(errorCode + " ERROR: " + errorShort)
Console.WriteLine(errorLong + vbCrLf)
Return "error"
Else
End If
'checkerror("check_09")
Dim item As XmlNode
item = root("item")
iteminfo = ("title: " + item("title").InnerText) + ("Quantity: " + item("Quantity").InnerText) + item("ListingDetails")("EndTime").InnerText + " GMT;" + " BuyItNow Price: " + item("BuyItNowPrice").InnerText
Dim objStreamWriter As StreamWriter
objStreamWriter = New StreamWriter("C:\ebay_LCD_smartie_interface\" + (param1) + ".txt", False)
objStreamWriter.WriteLine(iteminfo)
Return "done"
End Function