我希望利用C#,能从钉钉通讯录调用到用户信息,代码如下,但是运行时提示“未找到用户列表”,请给看看哪里有问题,多谢了;
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;
namespace SalaryCount
{
public partial class Form1 : BaseForm
{
private string appKey = "dingqnybw1hbp4lqyeety;
private string appSecret = "7fbCQHDPbQZ";
private IDingTalkClient client;
public Form1()
{
InitializeComponent();
client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/simplelist");
LoadData();
}
private void LoadData()
{
try
{
OapiUserSimplelistRequest request = new OapiUserSimplelistRequest();
request.DepartmentId = 1L; // 部门ID,根部门ID为1
OapiUserSimplelistResponse response = client.Execute(request, appKey, appSecret);
JObject responseObject = JObject.Parse(response.Body);
JArray userList = (JArray)responseObject["userlist"];
if (userList != null)
{
DataTable dt = new DataTable();
dt.Columns.Add("姓名");
dt.Columns.Add("部门");
dt.Columns.Add("手机号");
foreach (JObject user in userList)
{
dt.Rows.Add(user["name"], user["department"], user["mobile"]);
}
dataGridView1.DataSource = dt;
}
else
{
MessageBox.Show("未找到用户列表。");
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}