斯堪的纳维亚字符在Go语言的go-instagram API绑定中无法正常工作。

huangapple go评论90阅读模式
英文:

Scandinavian characters not working in go-lang go-instagram API bindings

问题

嗨,我正在努力理解这个开源库(https://github.com/carbocation/go-instagram/)中似乎存在的多字节支持问题。我正在使用下面的代码来获取关于瑞典语标签“blå”(蓝色)的信息。然而,当我尝试时,却得到一个空数组。

fmt.Println("Starting instagram download.")
client := instagram.NewClient(nil)
client.ClientID = "myid"
media, _, _ := client.Tags.RecentMedia("blå", nil)
fmt.Println(media)

我已经尝试通过浏览器使用API,发现有几张带有该标签的图片。我还尝试使用英文标签(如blue)的代码片段,也能返回最新的图片。如果有人能解释为什么会出现这种情况,我会很高兴。我想更新这个库,使其支持多字节,但我没有足够的Go语言知识。这是一个Go语言的问题还是库的问题?

谢谢。

英文:

Hi I'm trying to wrap my head around what seems to be a problem with multibyte support in this open source library (https://github.com/carbocation/go-instagram/). I am using the code below to retrieve information about the tag blue in swedish. How ever I get an empty array when trying.

fmt.Println("Starting instagram download.")
client := instagram.NewClient(nil)
client.ClientID = "myid"
media, _, _ := client.Tags.RecentMedia("blå", nil)
fmt.Println(media)

I have tried using the api trough the browser and there are several pictures tagged with the tag. I have also tried using the code snippet with tags in English like blue and that returns the latest pictures as well. I would be glad if any one could explain why this might happen. Id like to update the lib so it supports multi-byte but I haven't got the go knowledge required. Is this a go problem or a problem with the library?

Thank you

答案1

得分: 1

问题出在validTagName()函数中:

// 去除Instagram不接受的内容,例如连字符
func validTagName(tagName string) (bool, error) {
    // \W 匹配任何非单词字符
    reg, err := regexp.Compile(`\W`)
    if err != nil {
        return false, err
    }

    if reg.MatchString(tagName) {
        return false, nil
    }

    return true, nil
}

在Go语言中,\W精确匹配[^0-9A-Za-z_]。这个验证检查是不正确的。

英文:

The problem is in validTagName():

// Strip out things we know Instagram won't accept. For example, hyphens.
func validTagName(tagName string) (bool, error) {
	//\W matches any non-word character
	reg, err := regexp.Compile(`\W`)
	if err != nil {
		return false, err
	}

	if reg.MatchString(tagName) {
		return false, nil
	}

	return true, nil
}

In Go, \W matches precisely [^0-9A-Za-z_]. This validation check is incorrect.

huangapple
  • 本文由 发表于 2015年11月21日 22:51:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/33844707.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定