Phase 8 part 2: who links to you, from Bing
With a Bing Webmaster key, Supermarket reads once a week (or on Read now) how many links Bing knows to each page of the site, and for the 25 most linked pages, the pages that link and their anchor text, into the backlinks table. SEO → Links lists the linking sites, new ones first, with the pages they link to and their link text; without a key it says how to get one. A refused key keeps the last read, with the error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Package bing reads Bing Webmaster Tools through its API
|
||||
// (https://learn.microsoft.com/en-us/bingwebmaster/getting-access):
|
||||
// a site's traffic, its searches and its crawl issues. It only reads.
|
||||
// a site's traffic, its searches, its crawl issues and the links to it.
|
||||
// It only reads.
|
||||
package bing
|
||||
|
||||
import (
|
||||
@@ -38,8 +39,11 @@ func (c *Client) WithBase(u string) *Client {
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) get(ctx context.Context, method, site string, out any) error {
|
||||
func (c *Client) get(ctx context.Context, method, site string, out any, extra ...string) error {
|
||||
q := url.Values{"apikey": {c.key}, "siteUrl": {site}}
|
||||
for i := 0; i+1 < len(extra); i += 2 {
|
||||
q.Set(extra[i], extra[i+1])
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.base+"/"+method+"?"+q.Encode(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -135,3 +139,37 @@ func (c *Client) CrawlIssues(ctx context.Context, site string) ([]CrawlIssue, er
|
||||
err := c.get(ctx, "GetCrawlIssues", site, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// LinkCount is how many links Bing knows to one page of the site.
|
||||
type LinkCount struct {
|
||||
URL string `json:"Url"`
|
||||
Count int `json:"Count"`
|
||||
}
|
||||
|
||||
// LinkCounts are one page (from 0) of the site's pages with the number of
|
||||
// links to each, and how many pages of results there are.
|
||||
func (c *Client) LinkCounts(ctx context.Context, site string, page int) ([]LinkCount, int, error) {
|
||||
var out struct {
|
||||
Links []LinkCount `json:"Links"`
|
||||
TotalPages int `json:"TotalPages"`
|
||||
}
|
||||
err := c.get(ctx, "GetLinkCounts", site, &out, "page", strconv.Itoa(page))
|
||||
return out.Links, out.TotalPages, err
|
||||
}
|
||||
|
||||
// Link is a page that links to the site, with its anchor text.
|
||||
type Link struct {
|
||||
URL string `json:"Url"`
|
||||
Anchor string `json:"AnchorText"`
|
||||
}
|
||||
|
||||
// URLLinks are one page (from 0) of the pages linking to one page of the
|
||||
// site, and how many pages of results there are.
|
||||
func (c *Client) URLLinks(ctx context.Context, site, target string, page int) ([]Link, int, error) {
|
||||
var out struct {
|
||||
Details []Link `json:"Details"`
|
||||
TotalPages int `json:"TotalPages"`
|
||||
}
|
||||
err := c.get(ctx, "GetUrlLinks", site, &out, "link", target, "page", strconv.Itoa(page))
|
||||
return out.Details, out.TotalPages, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user