2010-04-13 83 views
0

我正在玩新的雅虎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

放弃一些虚拟的数据当我运行此我得到一个错误authenticaion(需要登录到雅虎)这是罚款显然是我在互联网上乱搞。不过,我想从一个ruby脚本中调用它。任何想法我如何去认证?我似乎只能找到一些网络启用版本。

回答

0

您可以试试Mechanize gem。我过去曾将其用于其他已认证的服务 。

0

我也会推荐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 
0

您可以尝试omniauth-yahoo进行授权,但它看起来不支持在过期后获取新令牌。

-1

公共功能ScanColumns(SHEETNAME作为字符串,thisMany作为双,ShowWhat作为字符串)

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