2015-10-21 77 views
0

如何使用Salesforce Marketing Cloud API连接我的SQL Server数据库。我需要使用C#来执行HTTP POST请求来获取访问令牌,但我不知道如何去做。我需要在C#中运行此示例代码:如何使用Salesforce Marketing Cloud API连接我的SQL服务器

POST https://auth.exacttargetapis.com/v1/requestToken 
Content-Type: application/json 
{ 
    "clientId": "gyjzvytv7ukqtfn3x2qdyfsn", 
    "clientSecret": "************" 
} 

我使用SSIS 2008R2,我想编写C#代码,使API调用的确切目标API连接到SQL Server数据库。因为我想将数据从SQL服务器提取到营销云。我没有找到任何有关使用SSIS连接营销云的文章..... salesforce营销云休息API或FuelSDK看起来像只支持.net 4或更高......

+0

这个问题非常广泛。从这里开始:http://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c –

+0

谢谢,我之前阅读过,但大多数解决方案都使用.net 4或更高版本,所以我正在寻找是否有机会使用.net 3.5 ....但它看起来很难... – Leo

回答

0

这对我有用。在某些时候将clientId和客户机密钥移至web.config。

public static async Task<string> getAuth() 
    { 
     var clientId = "asdfasdfasdfasdfasdfasdf"; 
     var clientSecret = "asdfasdfasdfasdfasdf"; 
     using (var client = new HttpClient()) 
     { 
      var values = new Dictionary<string, string> 
      { 
       {"clientId", clientId}, 
       {"clientSecret", clientSecret} 
      }; 

      var content = new FormUrlEncodedContent(values); 

      var response = await client.PostAsync(string.Format("https://auth.exacttargetapis.com/v1/requestToken"), content); 

      var responseString = await response.Content.ReadAsStringAsync(); 
      return responseString; 
     } 
    }