Graph API usage from C++ SDK

Our Facebook SDK for Games on Windows contains many helper functions that make it easy to call any Graph API endpoint. This allows you to build social context into your PC Game.

Making API Calls

Here's one example on how to find friends of the connected player.

    auto requestId1 = fbg_GraphAPI_GET(path, parameters); // For GET requests
    auto requestId2 = fbg_GraphAPI_POST(path, parameters); // For POST requests
    auto requestId3 = fbg_GraphAPI_DELETE(path, parameters); // For DELETE requests
    

Here's an example of how to handle the response, based on fbg_Message_ type:

    // Example response message
    
    switch (fbg_Message_GetType(message)) {
  	// ...
    case fbgMessage_AccessToken: {
    	auto handle = fbg_Message_GraphAPIResponse(message);
    	auto requestId = fbg_Message_GetRequestId(message);
    	char response[2056];
    	fbg_GraphAPIResponse_GetRaw(handle, response, 2056);
    	printf("Graph API Response for request %s: %s\n", requestId, response);
    	break;
    }
  

The response can have any of these types:

  • fbgMessage_Unknown
  • fbgMessage_AccessToken
  • fbgMessage_FeedShare
  • fbgMessage_Purchase
  • fbgMessage_HasLicense
  • fbgMessage_AppRequest
  • fbgMessage_OVRAccessToken
  • fbgMessage_GameStats_FetchResponse
  • fbgMessage_GameStats_UpdateResponse
  • fbgMessage_GraphAPIResponse
  • fbgMessage_Livestream_Create
  • fbgMessage_Livestream_Publish

Finding Friends

To find friends of the logged in user, use the Graph API example above against our /user/friends endpoint