使用ActionType.SEND/ASKFOR时,如何获取GameRequestContent所需的objectId?
Got it, let's clear up the confusion around getting the objectId you need when using ActionType.SEND or ActionType.ASKFOR in your game. Since you're restricted to pre-built objects (no custom ones allowed in newer versions), here's a straightforward breakdown:
1. Understand Pre-built Object IDs
Pre-built Open Graph objects (like game items, levels, achievements) have standardized identifiers you can retrieve via the Graph API or reference from official game development resources. These are exactly the objectId values you need to pass to setObjectId().
2. Retrieve Object IDs via Graph API
The most reliable way to get valid objectIds for your app is to query the Graph API directly:
Use the endpoint
GET /me/objects/{object-type}where{object-type}is the pre-built object category you need (e.g.,game.item,game.level,game.achievement).This call will return a list of all pre-built objects available for your app. Each entry in the response includes an
idfield — that's your targetobjectId.Example request (replace
{object-type}with your desired category):GET /me/objects/game.item?access_token=YOUR_APP_ACCESS_TOKEN
3. Use Known Global IDs for Common Objects
For widely used pre-built objects (like generic game props), Facebook provides fixed global IDs that you can directly reference. These are often listed in Facebook's Game Developer documentation under sections about pre-built Open Graph objects.
4. Clarifying the Tool Link Confusion
The tool link you mentioned asks for an ActionType ID, but that's for custom action types — which you don't need here. Since you're using the pre-built SEND/ASKFOR actions, you don't need an ActionType ID at all. Focus entirely on retrieving the pre-built object's ID as outlined above.
Important Notes
- Make sure your app has the required permissions (like game-specific publish permissions) to access these objects via the API.
- Never use custom-created object IDs — newer API versions only allow pre-built objects for these actions, so custom IDs will throw errors.
内容的提问来源于stack exchange,提问作者Umer Khaldi

