伐木问题 - 销售人员C#
这是代码片段 错误:{“ error”:“ invalid_client_id”,“ error_description”:“客户端标识符无效”} 连接通过正确的客户端,客户端,用户名,密码 传递安全风口空的
运气我们无需SecurityToken即可连接
public void Login()
{
String jsonResponse;
try
{
using (var client = new HttpClient())
{
var request = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "grant_type","password"},
{ "client_id", ClientId},
{ "client_secret", ClientSecret},
{ "username", Username},
{ "password", Password + Token}
});
request.Headers.Add("X-PreetyPrint", "1");
var response = client.PostAsync(LOGIN_ENDPOINT,
request).Result;//client.SendAsync(request);//
jsonResponse = response.Content.ReadAsStringAsync().Result;//
Content.ReadAsStringAsync();
}
}
catch (Exception ex)
{
throw ex;
}
var values = JsonConvert.DeserializeObject<Dictionary<string, string>>
(jsonResponse);
AuthToken = values["access_token"];
InstanceUrl = values["instance_url"];
Console.WriteLine("Auth Token = " + AuthToken);
Console.WriteLine("Instance Url = " + InstanceUrl);
}
Here is the code snippet
Error: {"error":"invalid_client_id","error_description":"client identifier invalid"}
connecting passing correct clientid, clientsecret, username, password
passing securityToken empty
Any luck can we connect without securityToken
public void Login()
{
String jsonResponse;
try
{
using (var client = new HttpClient())
{
var request = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "grant_type","password"},
{ "client_id", ClientId},
{ "client_secret", ClientSecret},
{ "username", Username},
{ "password", Password + Token}
});
request.Headers.Add("X-PreetyPrint", "1");
var response = client.PostAsync(LOGIN_ENDPOINT,
request).Result;//client.SendAsync(request);//
jsonResponse = response.Content.ReadAsStringAsync().Result;//
Content.ReadAsStringAsync();
}
}
catch (Exception ex)
{
throw ex;
}
var values = JsonConvert.DeserializeObject<Dictionary<string, string>>
(jsonResponse);
AuthToken = values["access_token"];
InstanceUrl = values["instance_url"];
Console.WriteLine("Auth Token = " + AuthToken);
Console.WriteLine("Instance Url = " + InstanceUrl);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要登录而无需安全令牌,您需要在受信任的网络上。例如,如果您的Office / VPN /应用程序服务器具有静态IP-您的Salesforce管理员可以将其添加到设置中 - &gt;网络访问。更多信息: https://https://help.salesforce.com/sarticleview.com/sarticleview ?
密码。阅读有关JWT和(无耻的插件): https://stackoverflow.com/a/a/72119994/313628 href =“ https://stackoverflow.com/a/63897503/313628”> https://stackoverflow.com/a/63897503/313628
To login without security token you need to be on trusted network. For example if your office / VPN / application server has static IP - your Salesforce admin can add it to Setup -> Network Access. More info: https://help.salesforce.com/s/articleView?id=000333031&type=1
If the IP is not static and this has to be done completely server-side (withotu human logging in in the browser and authorising your app)... you could try to login without password. Read up about JWT and (shameless plug): https://stackoverflow.com/a/72119994/313628, https://stackoverflow.com/a/63897503/313628