SendFriendMessageRequest

Sends a message to one or more game friend(s). A game friend is someone in the players social network who also plays the game.

View interactive version here

Request Parameters

Parameter Required Type Description
friendIds Yes string[] One or more friend ID's. This can be supplied as a single string, or a JSON array
message Yes string The message to send

Response Parameters

A response to a send friend message request.

Parameter Type Description
scriptData ScriptData A JSON Map of any data added either to the Request or the Response by your Cloud Code

Nested types

ScriptData

A collection of arbitrary data that can be added to a message via a Cloud Code script.

Parameter Type Description
myKey string An arbitrary data key
myValue JSON An arbitrary data value.

Error Codes

Key Value Description
friendId NOT_FRIEND The friend ID passed is not linked to the current player as a game friend
friendId INVALID The value passed is not a valid ID

Code Samples

C#

    using GameSparks.Api;
    using GameSparks.Api.Requests;
    using GameSparks.Api.Responses;
    ...
    new SendFriendMessageRequest()
        .SetFriendIds(friendIds)
        .SetMessage(message)
        .Send((response) => {
        GSData scriptData = response.ScriptData; 
        });

ActionScript 3

    import com.gamesparks.*;
    import com.gamesparks.api.requests.*;
    import com.gamesparks.api.responses.*;
    import com.gamesparks.api.types.*;
    ...

    gs.getRequestBuilder()
        .createSendFriendMessageRequest()
        .setFriendIds(friendIds)
        .setMessage(message)
        .send(function(response:com.gamesparks.api.responses.SendFriendMessageResponse):void {
        var scriptData:ScriptData = response.getScriptData(); 
        });

Objective-C

    #import "GS.h"
    #import "GSAPI.h"
    ...
    GSSendFriendMessageRequest* request = [[GSSendFriendMessageRequest alloc] init];
    [request setFriendIds:friendIds;
    [request setMessage:message;
    [request setCallback:^ (GSSendFriendMessageResponse* response) {
    NSDictionary* scriptData = [response getScriptData]; 
    }];
    [gs send:request];

C++


    #include <GameSparks/generated/GSRequests.h>
    using namespace GameSparks::Core;
    using namespace GameSparks::Api::Responses;
    using namespace GameSparks::Api::Requests;
    ...

    void SendFriendMessageRequest_Response(GS& gsInstance, const SendFriendMessageResponse& response) {
    GSData scriptData = response.getScriptData(); 
    }
    ......

    SendFriendMessageRequest request(gsInstance);
    request.SetFriendIds(friendIds)
    request.SetMessage(message)
    request.Send(SendFriendMessageRequest_Response);

Java

import com.gamesparks.sdk.api.autogen.GSRequestBuilder.SendFriendMessageRequest;
import com.gamesparks.sdk.api.autogen.GSResponseBuilder.SendFriendMessageResponse;
import com.gamesparks.sdk.api.autogen.GSTypes.*;
import com.gamesparks.sdk.api.GSEventListener;

...
gs.getRequestBuilder().createSendFriendMessageRequest()
    .setFriendIds(friendIds)
    .setMessage(message)
    .send(new GSEventListener<SendFriendMessageResponse>() {
        @Override
        public void onEvent(SendFriendMessageResponse response) {
            GSData scriptData = response.getScriptData(); 
        }
    });

Cloud Code


    var request = new SparkRequests.SendFriendMessageRequest();
    request.friendIds = ...;
    request.message = ...;
    var response = request.Send();

var scriptData = response.scriptData; 
Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here