获取用户 ID 的配置文件 ID

Getting the profileid for a userid

在我们公司,我们创建了一个自定义 Issues 应用程序。除了在 Web 界面中使用此应用程序之外,我们还希望能够通过 git 提交挂钩自动更改问题的状态(新的、已确认的、测试的、已解决的……)。基础工作正常(即更改状态、添加注释等),但我们还想将当前项目的责任更改为特定用户。在这种特殊情况下,它是该项目的创建者。

我的第一次尝试如下:

var appid = 1234; var itemid = 1;
var item = podio.ItemService.GetItemByAppItemId(appid, itemid);
var update = new Item {ItemId = item.ItemId};

var creator = item.CreatedBy.Id;
var resp = update.Field<ContactItemField>("responsibility");
resp.ContactIds = new List<int>{creator.Value};

//change some other fields as well

podio.ItemService.UpdateItem(update);

这会抛出一个 "Object not found" 异常,因为在 resp.ContactIds 中不能设置 UserId 而是 ProfileId

然后我尝试通过

获取项目创建者的 ProfileId
podio.ContactService.GetUserContactField(creator.Value, "profile_id");

但这也会抛出异常“(此方法不允许作为应用程序进行身份验证”)。

那么当我使用身份验证作为应用程序时,如何才能为用户获取适当的配置文件 ID?

好的,我找到了一个解决方法,不确定是否适用于其他情况,但它适用于当前情况。

我没有使用 C# 界面为 ContactItemField 设置 ContactIds,而是直接设置 json 值。

var appid = 1234; var itemid = 1;
var item = podio.ItemService.GetItemByAppItemId(appid, itemid);
var update = new Item {ItemId = item.ItemId};

var creator = item.CreatedBy.Id;
var resp = update.Field<ContactItemField>("responsibility");
resp.ContactIds = new List<int>(); // set to an empty list, so that resp.Values is initialized to an empty JArray

var u = new JObject { {"value", new JObject { {"type" , "user" }, {"id", creator } } } };
responsibleField.Values.Add(u); //add the new user to the Values of the field

//change some other fields as well
podio.ItemService.UpdateItem(update);

如果我将 value 设置为 user 我可以使用已知的 userid 并且服务器上的 API 负责查找。