Craftercms - Social:能否指定"create comment" API获取的用户属性?
Great question! Let me walk you through how to tailor the user.attributes field in the "create comment" API response to your needs, based on CrafterCMS v3.0's Social API documentation:
Use the
fieldsparameter to pick specific attributes
When sending your POST request to the comment creation endpoint, add thefieldsquery parameter to explicitly list which user attributes you want included.For example, if you only need the
displayNameandprofilePictureUrlattributes underuser.attributes, your request URL would look something like this:/api/3/social/ugc/comments/create?fields=user.attributes.displayName,user.attributes.profilePictureUrlThis tells the API to only return those two attributes in the response's user object.
Use
excludeFieldsto omit unwanted attributes
If you want most user attributes but need to leave out a few specific ones, use theexcludeFieldsparameter instead. Say you don't want theprivateNotesattribute returned—your request would include:/api/3/social/ugc/comments/create?excludeFields=user.attributes.privateNotesDefault behavior to keep in mind
If you don't specify either
fieldsorexcludeFields, the API will return all available user attributes stored in the system for that user by default.
Just a quick heads-up: You can only request attributes that are actually saved for the user in your CrafterCMS instance—you won't be able to pull attributes that weren't stored in the first place.
内容的提问来源于stack exchange,提问作者Isai Ulate Sancho

