【问题标题】:Yahoo authentication雅虎认证
【发布时间】:2010-04-13 13:58:20
【问题描述】:

我正在使用新的 yahoo API。我想使用以下地址废弃一些虚拟数据

http://query.yahooapis.com/v1/public/yql?q=desc%20social.updates.search&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc

当我运行此程序时,我收到一个身份验证错误(需要登录到 Yahoo)这显然对我在互联网上乱搞来说很好。但是,我想从 ruby​​ 脚本中调用它。任何想法我如何进行身份验证?我似乎只能找到一些启用网络的版本。

【问题讨论】:

    标签: ruby yahoo yahoo-pipes


    【解决方案1】:

    您可以为此尝试Mechanize gem。我已将其用于其他经过身份验证的服务 过去。

    【讨论】:

      【解决方案2】:

      我还推荐httparty -- 用它来映射 JSON 服务非常容易。试试这个:

      require 'rubygems'
      require 'httparty'
      
      class Yahoo
        include HTTParty
        # i don't think you need auth for this endpoint -- but if you do, uncomment below and fill it in
        #basic_auth 'username', 'password'
        format :json
      
        def self.load
          self.get 'http://query.yahooapis.com/v1/public/yql', :query => {:q => 'desc social.updates.search', :format => 'json', :diagnostics => true, :env => 'store://datatables.org/alltableswithkeys'}
        end
      end
      
      puts Yahoo.load
      

      【讨论】:

        【解决方案3】:

        您可以尝试omniauth-yahoo进行授权,但发现不支持过期后获取新令牌。

        【讨论】:

          【解决方案4】:

          公共函数 ScanColumns(SheetName As String, thisMany As Double, ShowWhat As String)

          e = 0
          
          For a = 1 To thisMany
              aa = Application.WorksheetFunction.CountA(Sheets(SheetName).Cells(1, a).EntireColumn)
              If aa > 0 Then
                  r = a
                  If e = 0 Then
                      e = a
                  End If
              End If
              Next a
          
              If ShowWhat = "MIN" Then
                  ScanColumns = e
              End If
              If ShowWhat = "MAX" Then
                  ScanColumns = r
              End If
          
          End Function
          
          Public Function ScanRows(SheetName As String, thisMany As Double, ShowWhat As String)
          
              e = 0
          
              For a = 1 To thisMany
                  aa = Application.WorksheetFunction.CountA(Sheets(SheetName).Cells(a, 1).EntireRow)
                  If aa > 0 Then
                      r = a
                      If e = 0 Then
                          e = a
                      End If
                  End If
                  Next a
          
                  If ShowWhat = "MIN" Then
                      ScanRows = e
                  End If
                  If ShowWhat = "MAX" Then
                      ScanRows = r
                  End If
          
              End Function
          
              Public Function FindInArea(SheetName As String, startRow As String, endRow As String, startCol As String, endCol As String, FindThis As String, ShowWhat As String)
          
                  CalendarMonthFormat1 = "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec,"
                  CalendarMonthFormat2 = "January, Feburary,March,April,May,June,July,August,September,October,November,December,"
          
                  earliestDate = 999999999
                  latestDate = 0
          
          
                  If Left(FindThis, 7) = "[LENGTH" Then
                      LengthLook = Replace(FindThis, "[LENGTH", "")
                      LengthLook = Replace(LengthLook, "]", "")
                  End If
          
          
                  For a = startRow To endRow
                      For b = startCol To endCol
                          ThisCell = Sheets(SheetName).Cells(a, b)
                          thisCellAddr = Sheets(SheetName).Cells(a, b).Address
                          If ThisCell = FindThis Then
                              addrList = addrList & "[" & thisCellAddr & "]"
                              rc_list = rc_list & "[" & a & "," & b & "]"
                              c = c + 1
                          End If
                          If FindThis = "[MONTHS1]" Then
                              If ThisCell <> "" And InStr(LCase(CalendarMonthFormat1), LCase((ThisCell) & ",")) > 0 And Len(ThisCell) = 3 Then
                                  addrList = addrList & "[" & thisCellAddr & "]"
                                  rc_list = rc_list & "[" & a & "," & b & "]"
                                  c = c + 1
                              End If
                          End If
                          If FindThis = "[MONTHS2]" Then
                              If ThisCell <> "" And InStr(LCase(CalendarMonthFormat2), LCase((ThisCell) & ",")) > 0 Then
                                  addrList = addrList & "[" & thisCellAddr & "]"
                                  rc_list = rc_list & "[" & a & "," & b & "]"
                                  c = c + 1
                              End If
                          End If
                          If FindThis = "[DATEFORMAT]" Then
                              If InStr(ThisCell, "/") > 0 Then
                                  slash_count = 0
                                  For sc = 1 To Len(ThisCell)
                                      If Mid(ThisCell, sc, 1) = "/" Then
                                          slash_count = slash_count + 1
                                      End If
                                      Next sc
                                      If slash_count = 2 Then
                                          On Error Resume Next
                                          D = Day(ThisCell)
                                          M = Month(ThisCell)
                                          Y = Year(ThisCell)
                                          If D > 0 And M > 0 And Y > 0 Then
                                              addrList = addrList & "[" & thisCellAddr & "]"
                                              rc_list = rc_list & "[" & a & "," & b & "]"
                                              c = c + 1
                                              If earliestDate > DateValue(ThisCell) Then
                                                  earliestDate = DateValue(ThisCell)
                                                  If Len(D) = 1 Then
                                                      D = "0" & D
                                                  End If
                                                  If Len(M) = 1 Then
                                                      M = "0" & M
                                                  End If
                                                  eDateLocation = thisCellAddr
                                                  eDate_Format = D & "-" & M & "-" & Y
                                              End If
          
                                              If latestDate < DateValue(ThisCell) Then
                                                  latestDate = DateValue(ThisCell)
                                                  If Len(D) = 1 Then
                                                      D = "0" & D
                                                  End If
                                                  If Len(M) = 1 Then
                                                      M = "0" & M
                                                  End If
                                                  lDateLocation = thisCellAddr
                                                  lDate_Format = D & "-" & M & "-" & Y
                                              End If
                                          End If
                                      End If
                                  End If
                              End If
          
                              If Left(FindThis, 7) = "[LENGTH" Then
                                  If Len(ThisCell) = Val(LengthLook) Then
                                      addrList = addrList & "[" & thisCellAddr & "]"
                                      rc_list = rc_list & "[" & a & "," & b & "]"
                                      c = c + 1
                                  End If
                              End If
                              If FindThis = "[DECIMAL]" Then
                                  If InStr((ThisCell), ".") > 0 Then
                                      addrList = addrList & "[" & thisCellAddr & "]"
                                      rc_list = rc_list & "[" & a & "," & b & "]"
                                      c = c + 1
                                  End If
                              End If
                              If FindThis = "[PERC]" Then
                                  If InStr((ThisCell), ".") > 0 And ThisCell <> "" And ThisCell <> 0 And Val(ThisCell) >= -1 And Val(ThisCell) <= 1 Then
                                      addrList = addrList & "[" & thisCellAddr & "]"
                                      rc_list = rc_list & "[" & a & "," & b & "]"
                                      c = c + 1
                                  End If
                              End If
          
          
          
                              Next b
                              Next a
          
                              If ShowWhat = "COUNT" Then
                                  FindInArea = c
                              End If
                              If ShowWhat = "ADDR" Then
                                  FindInArea = addrList
                              End If
                              If ShowWhat = "RC" Then
                                  FindInArea = rc_list
                              End If
                              If ShowWhat = "EARLIESTDATE" Then
                                  FindInArea = eDate_Format
                              End If
                              If ShowWhat = "EARLIESTDATEADDR" Then
                                  FindInArea = eDateLocation
                              End If
                              If ShowWhat = "LATESTDATE" Then
                                  FindInArea = lDate_Format
                              End If
                              If ShowWhat = "LATESTDATEADDR" Then
                                  FindInArea = lDateLocation
                              End If
                          End Function
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-01-14
            • 1970-01-01
            • 2018-11-25
            • 1970-01-01
            • 2015-03-03
            • 1970-01-01
            • 1970-01-01
            • 2011-11-21
            相关资源
            最近更新 更多