我们想读取钉钉通讯录人员信息,显示在C#表单的datagridview内,直接复制了钉钉提供的读取代码,但运行时报错如截图,请给分析一下原因,并优化一下代码,谢谢;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
//using DingTalk.Api;
//using DingTalk.Api.Request;
//using Newtonsoft.Json.Linq;
//using DingTalk.Api.Response;
using PlatBaseClass;
//using Newtonsoft.Json;
using Tea;
using Tea.Utils;
namespace SalaryCount
{
public partial class Form1 : BaseForm
{
private string appKey = "dingqnybw1hbp4lqyeqp";
private string appSecret = "UfXT4o9RG0CdKIP2sXy8NhuimP24tQKGrBRYpkLo1R8y0PLy_yfeI7fbCQHDPbQZ";
//private IDingTalkClient client;
public Form1()
{
InitializeComponent();
//client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/list");
}
public class Sample
{
public static AlibabaCloud.SDK.Dingtalkcontact_1_0.Client CreateClient()
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config();
config.Protocol = "https";
config.RegionId = "central";
return new AlibabaCloud.SDK.Dingtalkcontact_1_0.Client(config);
}
public static void Main(string[] args)
{
AlibabaCloud.SDK.Dingtalkcontact_1_0.Client client = CreateClient();
AlibabaCloud.SDK.Dingtalkcontact_1_0.Models.GetUserHeaders getUserHeaders = new AlibabaCloud.SDK.Dingtalkcontact_1_0.Models.GetUserHeaders();
getUserHeaders.XAcsDingtalkAccessToken = "c4205c0dbd5b34179090219fbac72872";
try
{
client.GetUserWithOptions("ding6f12d1f8a725562abc961a6cb783455b", getUserHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
}
catch (TeaException err)
{
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
catch (Exception _err)
{
TeaException err = new TeaException(new Dictionary<string, object>
{
{ "message", _err.Message }
});
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}