ale*_*lex 8 github github-api graphql
我一直在尝试通过 GitHub 公开的 GraphQL API 从我的存储库获取开放图形图像,但我总是找回我的头像。我尝试查询存储库节点、搜索和用户节点,但无济于事。
例如,对于查询:
query {
repository(name: "rust-algorithms", owner: "alexfertel") {
openGraphImageUrl
nameWithOwner
}
}
Run Code Online (Sandbox Code Playgroud)
我得到:
query {
repository(name: "rust-algorithms", owner: "alexfertel") {
openGraphImageUrl
nameWithOwner
}
}
Run Code Online (Sandbox Code Playgroud)
您可以看出它给出的是头像,而不是 GitHub 为存储库生成的开放图形图像。
有没有一种方法可以在不涉及抓取 GitHub 的情况下获取此图像?
小智 16
一般格式为:
https://opengraph.githubassets.com/<any_hash_number>/<owner>/<repo>
感谢 Reddit 上的用户 @msfjarvis
任意哈希值
我们可以在这里使用任何数字或字符串。这实际上是告诉API这是版本。最好使用哈希,因为这样它总是会给出更新的图像。但我们可以使用任何字符串,如1、a、 或1a。如果我们总是使用1,否则a它不会提供更新的图像。