2012-12-06 30 views
0

我正在致力於一些C#項目,使API調用Adwords來下載數據。谷歌Adwords API調用通過C#下載數據

我已經通過使用獲得訪問令牌:

WebRequest webRequest = HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin"); 
     webRequest.Method = "POST"; 
     webRequest.ContentType = "application/x-www-form-urlencoded"; 

     string postParams = 

      "accountType=" + HttpUtility.UrlEncode("GOOGLE") + 
      "&Email=" + HttpUtility.UrlEncode("[email protected]") + 
      "&Passwd=" + HttpUtility.UrlEncode("xxxx") + 
      "&service=" + HttpUtility.UrlEncode("adwords") + 
      "&source=" + HttpUtility.UrlEncode(string.Format("{0}-{1}-{2}", "sample1", 
       "sample2", "1")); 

     byte[] postBytes = Encoding.UTF8.GetBytes(postParams); 
     webRequest.ContentLength = postBytes.Length; 

     using (Stream strmReq = webRequest.GetRequestStream()) 
     { 
      strmReq.Write(postBytes, 0, postBytes.Length); 
     } 

     string retVal = ""; 
     try 
     { 
      WebResponse response = webRequest.GetResponse(); 

      using (StreamReader reader = new StreamReader(response.GetResponseStream())) 
      { 
       string sResponse = reader.ReadToEnd(); 
       string[] splits = sResponse.Split('\n'); 
       foreach (string split in splits) 
       { 
        string[] subsplits = split.Split('='); 
        if (subsplits.Length >= 2 && subsplits[0] == "Auth") 
        { 
         retVal = subsplits[1]; 
        } 
       } 
      } 
     } 
     catch (WebException ex) 
     { 
      throw new ApplicationException("Could not generate auth token.", ex); 
     } 

我將不勝感激,如果有人可以讓我知道什麼是下一步進行API調用來下載數據。 https://developers.google.com/adwords/api/docs/guides/reporting

謝謝。

+0

您是否嘗試過使用客戶端庫? https://code.google.com/p/google-api-adwords-dotnet/ –

回答