雅虎认证

发布于 2024-08-28 12:20:51 字数 568 浏览 11 评论 0原文

我正在使用新的 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

当我运行此命令时,我收到身份验证错误(需要登录雅虎)显然对于我在互联网上闲逛来说没问题。不过我想从 ruby​​ 脚本中调用它。我有什么想法可以进行身份​​验证吗?我似乎只能找到一些网络版本。

I'm playing around with the new yahoo API. I'd like to scrap some dummy data using the following address

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

When I run this I get an authenticaion error (Need to be logged into Yahoo) This is fine obviously for me messing around on the internet. However I'd like to call this from a ruby script. Any ideas how I go about authenticating? I can only seem to find some web enabled version.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鹿港小镇 2024-09-04 12:20:52

公共函数 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

Public Function 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
一生独一 2024-09-04 12:20:51

您可以尝试使用 Mechanize gem 来实现此目的。我已将其用于其他经过身份验证的服务
在过去。

You might try the Mechanize gem for this. I've used it for other authenticated services
in the past.

GRAY°灰色天空 2024-09-04 12:20:51

我还推荐 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

I'd also recomment httparty -- It is ridiculously easy to map JSON services with this. Try this:

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
可是我不能没有你 2024-09-04 12:20:51

您可以尝试使用omniauth-yahoo进行授权,但是发现不支持过期后获取新的token。

You could try omniauth-yahoo for authorization, but it's seen didn't support get the new token after expired.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文