Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by maulik lathyia · Feb 14, 2020 at 10:41 AM · photonwebhooks

Photon webhooks not wokring

I did everything as shown in the guide but no events on play stream I tried everything but can't figure it out.

https://docs.microsoft.com/en-gb/gaming/playfab/features/multiplayer/photon/quickstart


Title id: B650D

webhook settings


Unity Logs :
https://prnt.sc/r25l3x

Code C#

using System.Collections.Generic;
using Photon.Pun;
using Photon.Realtime;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;


public class PlayFabAuthenticator : MonoBehaviourPunCallbacks
{


    public string _playFabPlayerIdCache;




    //Run the entire thing on awake
    public void Awake()
    {
          AuthenticateWithPlayFab();
        //  DontDestroyOnLoad(gameObject);
       
    }




    /*
     * Step 1
     * We authenticate current PlayFab user normally.
     * In this case we use LoginWithCustomID API call for simplicity.
     * You can absolutely use any Login method you want.
     * We use PlayFabSettings.DeviceUniqueIdentifier as our custom ID.
     * We pass RequestPhotonToken as a callback to be our next step, if
     * authentication was successful.
     */
    private void AuthenticateWithPlayFab()
    {
        Debug.Log("PlayFab authenticating using Custom ID...");


        PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest()
        {
            CreateAccount = true,
            CustomId = PlayFabSettings.DeviceUniqueIdentifier + "EDITOR"
        }, RequestPhotonToken, OnPlayFabError);
    }


    /*
    * Step 2
    * We request Photon authentication token from PlayFab.
    * This is a crucial step, because Photon uses different authentication tokens
    * than PlayFab. Thus, you cannot directly use PlayFab SessionTicket and
    * you need to explicitly request a token. This API call requires you to
    * pass Photon App ID. App ID may be hard coded, but, in this example,
    * We are accessing it using convenient static field on PhotonNetwork class
    * We pass in AuthenticateWithPhoton as a callback to be our next step, if
    * we have acquired token successfully
    */
    private void RequestPhotonToken(LoginResult obj)
    {
        Debug.Log("PlayFab authenticated. Requesting photon token...");


        //We can player PlayFabId. This will come in handy during next step
        _playFabPlayerIdCache = obj.PlayFabId;


        PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest()
        {
            PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime
        }, AuthenticateWithPhoton, OnPlayFabError);
    }


    /*
     * Step 3
     * This is the final and the simplest step. We create new AuthenticationValues instance.
     * This class describes how to authenticate a players inside Photon environment.
     */
    private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj)
    {
        Debug.Log("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + "  Authentication complete.");


        //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
        var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom };


        //We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
        customAuth.AddAuthParameter("username", _playFabPlayerIdCache);    // expected by PlayFab custom auth service


        //We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
        customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken);


        //We finally tell Photon to use this authentication parameters throughout the entire application.
        PhotonNetwork.AuthValues = customAuth;
        PhotonNetwork.ConnectUsingSettings();


    }


    private void OnPlayFabError(PlayFabError obj)
    {
        Debug.Log(obj.ErrorMessage);
    }


   


    // Add small button to launch our example code
    public void OnGUI()
    {
        if (GUILayout.Button("Execute Example ")) ExecuteExample();
    }


    public override void OnConnectedToMaster()
    {
        Debug.Log("connected  to master");
        PhotonNetwork.JoinOrCreateRoom("TestRoom", new RoomOptions() { }, TypedLobby.Default);


    }


   


    public override void OnCreatedRoom()
    {
        Debug.Log("room created");
    }


    public override void OnJoinedRoom()
    {
        Debug.Log("Joined room");
    }




    // Example code which raises custom room event, then sets custom room property
    private void ExecuteExample()
    {


        // Raise custom room event
        //var data = new Dictionary<string, object>() { { "Hello", "World" } };
        //var result = PhotonNetwork.RaiseEvent(15, data, true, new RaiseEventOptions()
        //{
        //    ForwardToWebhook = true,
        //});
        //LogMessage("New Room Event Post: " + result);


        // Set custom room property
        var properties = new ExitGames.Client.Photon.Hashtable() { { "CustomProperty", "It's Value" } };
        var expectedProperties = new ExitGames.Client.Photon.Hashtable();
        PhotonNetwork.CurrentRoom.SetCustomProperties(properties, expectedProperties);
        Debug.Log("New Room Properties Set");
    }


}
download.png (98.6 kB)
stream.png (74.4 kB)
Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by maulik lathyia · Feb 17, 2020 at 02:02 AM

Solution


Webhooks like "room join", "room left", "room created" works like a charm. But for Room event & Room Options Update, you need to do have

1 "IsPersistent" true in photon app settings

2 while updating room properties or raising event you need to mention WebFlags

I do it like this

Unity c#

Event

 public void SendEvent(byte _id,object[] _data)
    {
        var flags = new WebFlags(WebFlags.HttpForwardConst);
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Flags = flags,  Receivers = ReceiverGroup.All };
        SendOptions sendOptions = new SendOptions { Reliability = true };       
        PhotonNetwork.RaiseEvent(_id, _data, raiseEventOptions, sendOptions);
    }

Room Options

  public void SetRoomProperties(string _key,string _value)
    {
        if (PhotonNetwork.InRoom)
        {           
            ExitGames.Client.Photon.Hashtable roomProps = new ExitGames.Client.Photon.Hashtable();
            roomProps.Add(_key,_value);
            var expectedProperties = new ExitGames.Client.Photon.Hashtable();
            var flags = new WebFlags(WebFlags.HttpForwardConst);
            PhotonNetwork.CurrentRoom.SetCustomProperties(roomProps, expectedProperties, flags);
        }
        else
        {
            Debug.LogError("Not in room");
        }            
    }
Comment
Hamza Lazaar

People who like this

1 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Citrus Yan · Feb 17, 2020 at 06:19 AM 0
Share

Thanks for this info:)

avatar image Hamza Lazaar · Feb 17, 2020 at 10:56 AM 1
Share

Hi @maulik lathyia

Thank you for choosing Photon!

I'm glad you managed to find a solution on your own.
However, I wanted to clarify a small misunderstanding:

"IsPersistent" is not needed to forward RaiseEvent or SetProperties requests as HTTP webhooks.

avatar image

Answer by maulik lathyia · Feb 14, 2020 at 08:53 AM

It's Solved

Comment
Citrus Yan

People who like this

1 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jordan ♦ · Feb 14, 2020 at 09:14 PM 1
Share

@maulik lathyia Glad to hear you solved it! Would you mind giving a brief description of the solution you found for future reference?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    4 People are following this question.

    avatar image avatar image avatar image avatar image

    Related Questions

    Photon Webhook for RoomPropertyUpdated not firing. 1 Answer

    Validating room with external application 1 Answer

    webRpcResponse.Parameters are coming up null / RoomCreated not being called 4 Answers

    ,How to use PlayFab for storing persistent Photon Rooms? 1 Answer

    Photon WebHooks not triggered? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges