在localhost上设置Salesforce休息服务

时间:2015-08-31 19:44:59

标签: c# salesforce

我想要使用salesforce RESTful服务,但我无法进行身份验证。我做了什么 1)创建连接的应用程序
2)添加消费者密钥
3)增加消费者秘密密钥
4)增加安全令牌
4)Oauth范围到完全访问权限 5)回调网址设为failed with Clang

我收到此错误: {" error_description":"身份验证失败","错误":" invalid_grant"}

我的代码是

private static async void AuthenticateSfdcRestUser()
    {


        HttpClient authClient = new HttpClient();

        //defined remote access app - develop --> remote access --> new


        //set OAuth key and secret variables
        string sfdcConsumerKey = "XXXXX";
        string sfdcConsumerSecret = "XXXXX";

        //set to Force.com user account that has API access enabled
        string sfdcUserName = "XXXXX";
        string sfdcPassword = "XXXXX";
        string sfdcToken = "XXXXX";

        //create login password value
        string loginPassword = sfdcPassword + sfdcToken;

        HttpContent content = new FormUrlEncodedContent(new Dictionary<string, string>
            {
                {"grant_type","password"},
                {"client_id",sfdcConsumerKey},
                {"client_secret",sfdcConsumerSecret},
                {"username",sfdcUserName},
                {"password",loginPassword}
            }
             );

        HttpResponseMessage message = await authClient.PostAsync("https://login.salesforce.com/services/oauth2/token", content);

        string responseString = await message.Content.ReadAsStringAsync();

        JObject obj = JObject.Parse(responseString);
        oauthToken = (string)obj["access_token"];
        serviceUrl = (string)obj["instance_url"];

        //print response values
        Console.WriteLine(string.Format("The token value is {0}", responseString));
        Console.WriteLine("");
        Console.WriteLine("Press [Enter] to continue ...");
        Console.ReadLine();
    }

0 个答案:

没有答案