【问题标题】:getting error when adding my site url to google webmaster tool将我的网站网址添加到谷歌网站管理员工具时出错
【发布时间】:2015-09-20 09:51:04
【问题描述】:

我正在使用这段代码,每次我在 c# 中遇到错误

Google.GData.Client.RequestSettings settings = new Google.GData.Client.RequestSettings("ProjektName", "E-MAIL", "PWD"); 
Google.WebmasterTools.WebmasterToolsRequest f = new Google.WebmasterTools.WebmasterToolsRequest(settings); 

GDataRequestException,执行身份验证请求返回意外结果:404

用于添加站点

Google.GData.Client.RequestSettings settings = new Google.GData.Client.RequestSettings("ProjektName", "E-MAIL", "PWD"); 
Google.WebmasterTools.WebmasterToolsRequest f = new Google.WebmasterTools.WebmasterToolsRequest(settings); 

Google.WebmasterTools.Sites site = new Google.WebmasterTools.Sites(); 
site.AtomEntry = new Google.GData.Client.AtomEntry(); 
site.AtomEntry.Content.Src = "http://www.example.com/"; 
site.AtomEntry.Content.Type = "text/plain"; 
Google.WebmasterTools.Sites newSite = f.AddSite(site); 

用于添加站点地图

Google.WebmasterTools.Sitemap sitemap = new Google.WebmasterTools.Sitemap(); 
sitemap.Id = "http://www.example.com/sitemap.xml"; 
sitemap.Categories.Add(new Google.GData.Client.AtomCategory("http://schemas.google.com/webmasters/tools/2007#site-info", new Google.GData.Client.AtomUri("http://schemas.google.com/g/2005#kind"))); 
sitemap.SitemapType = "WEB"; 
Google.WebmasterTools.Sitemap newSitemap = f.AddSitemap("http%3A%2F%2Fwww%2Eexample%2Ecom%2F", sitemap); 

谁能帮帮我

【问题讨论】:

    标签: c# gdata google-search-console


    【解决方案1】:

    GData API 几个月前已弃用,您需要切换到基于 Oauth2 的 API: 在https://developers.google.com/webmaster-tools/API Explorer 上查看更多信息。

    要使用新 API 获取包含 Python 的站点列表(我们没有 C# 示例,但这可以为您提供一个好主意):

    #!/usr/bin/python
    
    import httplib2
    
    from apiclient import errors
    from apiclient.discovery import build
    from oauth2client.client import OAuth2WebServerFlow
    
    
    # Copy your credentials from the console
    CLIENT_ID = 'YOUR_CLIENT_ID'
    CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
    
    # Check https://developers.google.com/webmaster-tools/v3/ for all available scopes
    OAUTH_SCOPE = 'https://www.googleapis.com/auth/webmasters.readonly'
    
    # Redirect URI for installed apps
    REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
    
    # Run through the OAuth flow and retrieve credentials
    flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
    authorize_url = flow.step1_get_authorize_url()
    print 'Go to the following link in your browser: ' + authorize_url
    code = raw_input('Enter verification code: ').strip()
    credentials = flow.step2_exchange(code)
    
    # Create an httplib2.Http object and authorize it with our credentials
    http = httplib2.Http()
    http = credentials.authorize(http)
    
    webmasters_service = build('webmasters', 'v3', http=http)
    
    # Retrieve list of websites in account
    site_list = webmasters_service.sites().list().execute()
    
    # Remove all unverified sites
    verified_sites_urls = [s['siteUrl'] for s in site_list['siteEntry'] if s['permissionLevel'] != 'siteUnverifiedUser']
    
    # Printing the urls of all sites you are verified for.
    for site_url in verified_sites_urls:
      print site_url
      # Retrieve list of sitemaps submitted
      sitemaps = webmasters_service.sitemaps().list(siteUrl=site_url).execute()
      if 'sitemap' in sitemaps:
        sitemap_urls = [s['path'] for s in sitemaps['sitemap']]
        print "  " + "\n  ".join(sitemap_urls)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      • 2014-08-29
      • 2012-03-20
      • 2013-11-16
      • 2011-04-20
      相关资源
      最近更新 更多