Loading ...
Sorry, an error occurred while loading the content.

Re: [ysearchboss] I'm switching to Geico, but here's what I have

Expand Messages
  • Rahul Hampole
    Hello Thanks for posting this detailed information. We will definitely work on providing more examples that work with the Win8 stack. If you have other code
    Message 1 of 2 , May 21, 2013
    View Source
    • 0 Attachment
      Hello
      Thanks for posting this detailed information. We will definitely work on providing more examples that work with the Win8 stack. If you have other code samples to share, please do so and we will add them in (with credit). 

      Best
      BOSS Team

      From: howardjosh1982 <howardjosh1982@...>
      Reply-To: "ysearchboss@yahoogroups.com" <ysearchboss@yahoogroups.com>
      Date: Saturday, May 18, 2013 5:02 PM
      To: "ysearchboss@yahoogroups.com" <ysearchboss@yahoogroups.com>
      Subject: [ysearchboss] I'm switching to Geico, but here's what I have

       

      Okay, so I personally have found trying to use Yahoo BOSS as the backbone of my Windows 8 application to be very painful. I am not by any means familiar with OAuth, but I have invested 40+ hours of my time trying to get familiar. I believe I have acquired a decent understanding of the process as a whole, but not cut down version Yahoo is likely using for searching. My alternative (one of the big 2) took about an hour to figure out and is producing what I need in order to progress in development. It costs 3x as much and yields virtually the same results. I would like to use Yahoo BOSS someday, but not as it is currently setup.

      @BOSS project team. Please get some Windows 8 relevant examples in the documentation. I believe there is a rather strict schema in play and it just doesn't gain anybody anything. I need OAuth solely for the purpose of letting you know who to bill for the request; that shouldn't be challenging.

      Here are some of the best examples I found for OAuth in windows 8. Both of which are documented as being extremely tolerant in their implementations; which is probably why I can't get it to work with Yahoo BOSS.

      This is probably the most elegant of the two:
      https://gist.github.com/tistaharahap/2282462

      https://login.live.com/login.srf?wa=wsignin1.0&wtrealm=code.msdn.microsoft.com&wreply=https%3a%2f%2fcode.msdn.microsoft.com%2fwindowsapps%2fTwitter-OAuth-Example-3a99967f%3fstoAI%3d10&wp=MBI_FED_SSL&wlcxt=microsoft%24microsoft%24microsoft

      Both of those links are to windows 8 relevant C# code samples. I am a visual basic hobbyist and believe I have effectively migrated the parts I cared about to the best of my ability. Hopefully someone can pick up where I left off and get this working.

      This is the event from a search button in a xaml.vb file:
      Private Async Sub getRequestToken_Click_1(sender As Object, e As RoutedEventArgs) Handles btnSearch.Tapped
      Dim targetURL As String = "http://yboss.yahooapis.com/ysearch/web?q=dogs"
      Dim consumerKey As String = "Your Key Here"
      Dim consumerSecretKey As String = "Your Secret Here"

      Dim nonce As String = OAuth.OAuthUtil.GetNonce()
      Dim timeStamp As String = OAuth.OAuthUtil.GetTimeStamp()

      Dim sigBaseStringParams As String = "oauth_consumer_key=" & consumerKey
      sigBaseStringParams += "&" & "oauth_nonce=" & nonce
      sigBaseStringParams += "&" & "oauth_signature_method=" & "HMAC-SHA1"
      sigBaseStringParams += "&" & "oauth_timestamp=" & timeStamp
      sigBaseStringParams += "&" & "oauth_version=1.0"
      Dim sigBaseString As String = "POST&"
      sigBaseString += Uri.EscapeDataString(targetURL) & "&" & Uri.EscapeDataString(sigBaseStringParams)

      Dim signature As String = OAuth.OAuthUtil.GetSignature(sigBaseString, consumerSecretKey)
      Dim responseText = Await OAuth.OAuthUtil.PostData(targetURL, sigBaseStringParams & "&oauth_signature=" & Uri.EscapeDataString(signature))
      Dim brk As String = "I put a breakpoint here, but never got what I needed so I never did anything beyond this point"
      End Sub

      This is the Visual Basic version of the OAuth routine found on the second link. You will notice that there are 2 GetSignature functions. I was commenting one out and trying another version from the first link.

      Imports System.Collections.Generic
      Imports System.Linq
      Imports System.Net.Http
      Imports System.Net.Http.Headers
      Imports System.Text
      Imports System.Threading.Tasks
      Imports Windows.Security.Cryptography
      Imports Windows.Security.Cryptography.Core
      Imports Windows.Storage.Streams

      Namespace OAuth
      Public Class OAuthUtil
      Public Shared Function GetNonce() As String
      Dim rand As New Random()
      Dim nonce As Integer = rand.Next(1000000000)
      Return nonce.ToString()
      End Function

      Public Shared Function GetTimeStamp() As String
      Dim ts As TimeSpan = DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0, 0)
      Return Convert.ToInt64(ts.TotalSeconds).ToString()
      End Function

      Public Shared Async Function PostData(url As String, postData__1 As String) As Task(Of String)
      Try
      Dim httpClient As New HttpClient()
      httpClient.MaxResponseContentBufferSize = Integer.MaxValue
      httpClient.DefaultRequestHeaders.ExpectContinue = False
      Dim requestMsg As New HttpRequestMessage()
      requestMsg.Content = New StringContent(postData__1)
      requestMsg.Method = New HttpMethod("POST")
      requestMsg.RequestUri = New Uri(url, UriKind.Absolute)
      'requestMsg.Content.Headers.ContentType = New MediaTypeHeaderValue("application/x-www-form-urlencoded")
      requestMsg.Content.Headers.ContentType = New MediaTypeHeaderValue("application/xml")
      Dim response = Await httpClient.SendAsync(requestMsg)
      Return Await response.Content.ReadAsStringAsync()
      Catch Err As Exception
      Throw
      End Try
      End Function

      Public Shared Function GetSignature(baseString As String, keyString As String, Optional requestTokenSecretKey As String = Nothing) As String
      Dim crypt = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1")
      Dim buffer = CryptographicBuffer.ConvertStringToBinary(baseString, BinaryStringEncoding.Utf8)
      Dim keyBuffer = CryptographicBuffer.ConvertStringToBinary(keyString, BinaryStringEncoding.Utf8)
      Dim key = crypt.CreateKey(keyBuffer)
      Dim sigBuffer = CryptographicEngine.Sign(key, buffer)
      Dim signature As String = CryptographicBuffer.EncodeToBase64String(sigBuffer)
      Return signature
      End Function

      Public Shared Function GetSignature(sigBaseString As String, consumerSecretKey As String, Optional requestTokenSecretKey As String = Nothing) As String
      Dim signingKey = String.Format("{0}&{1}", consumerSecretKey, If(Not String.IsNullOrEmpty(requestTokenSecretKey), requestTokenSecretKey, ""))
      Dim keyMaterial As IBuffer = CryptographicBuffer.ConvertStringToBinary(signingKey, BinaryStringEncoding.Utf8)
      Dim hmacSha1Provider As MacAlgorithmProvider = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1")
      Dim macKey As CryptographicKey = hmacSha1Provider.CreateKey(keyMaterial)
      Dim dataToBeSigned As IBuffer = CryptographicBuffer.ConvertStringToBinary(sigBaseString, BinaryStringEncoding.Utf8)
      Dim signatureBuffer As IBuffer = CryptographicEngine.Sign(macKey, dataToBeSigned)
      Dim signature As String = CryptographicBuffer.EncodeToBase64String(signatureBuffer)
      Return signature
      End Function
      End Class
      End Namespace

    Your message has been successfully submitted and would be delivered to recipients shortly.