heroiclabs / nakama-cocos2d-x-javascript

Cocos2d-x client for Nakama server written in JavaScript
https://heroiclabs.com/docs/
Apache License 2.0
8 stars 2 forks source link

Facebook friend import error #13

Closed jhyoo2 closed 2 years ago

jhyoo2 commented 2 years ago

Hi guys.

I have a problem while load facebook friend with nakama server.

(1) code → here is the code I using : I am using typescript. await client.importFacebookFriends(token, reset);

(2) result → when I using that code or code like below 스크린샷 2022-05-17 오후 5 58 31

Could it be a problem with cocos-creator SDK?

We are using Facebook api version 13.0, is there a version difference?

and I don’t know how to solve it.

Anyone can help me?

lugehorsam commented 2 years ago

@jhyoo2 can you share more details on the error? What is the exception message?

jhyoo2 commented 2 years ago

it shows like this.


temp1-b31e3.web.app/:1 Uncaught (in promise) Response {type: 'cors', url: 'https://www.chamelio.co.kr:7350/v2/friend/facebook?', redirected: false, status: 400, ok: false, …} body: (...) bodyUsed: false headers: Headers {} ok: false redirected: false status: 400 statusText: "" type: "cors" url: "https://www.chamelio.co.kr:7350/v2/friend/facebook?"

My guess is that this is a problem with the sdk. I'm using cocos-creator now and I'm importing the file uploaded in the example(https://github.com/heroiclabs/nakama-cocos2d-x-javascript). If you look at the "nakama-js.umd.js" file on this page, you will find the following.


    NakamaApi.prototype.importFacebookFriends = function (body, reset, options) {
        if (options === void 0) { options = {}; }
        if (body === null || body === undefined) {
            throw new Error("'body' is a required parameter but is null or undefined.");
        }
        var urlPath = "/v2/friend/facebook";
        var queryParams = {
            reset: reset,
        };
        var _body = null;
        _body = JSON.stringify(body || {});
        return this.doFetch(urlPath, "POST", queryParams, _body, options);
    };

I followed up a bit and found When you call a function"await client.importFacebookFriends(token, reset);", then the function above is called. However, the "token" is being passed as a "body". So, the value of _body at the end comes out as "true", and this value is passed to the subsequent function.

lugehorsam commented 2 years ago

Sorry @jhyoo2 I'm not following -- I don't see anywhere that we pass token instead of body: you can see here where we do the passing from the client to the inner api client https://github.com/heroiclabs/nakama-cocos2d-x-javascript/blob/master/NakamaSDK/nakama-js.umd.js#L2377

jhyoo2 commented 2 years ago

Yep, you just picked the right location. If you look at the location you sent, it appears that you are receiving a session object that has a token variable as a parameter. However, if you actually print the log, the session is just output as a string type variable with a token value.

lugehorsam commented 2 years ago

@jhyoo2 okay, can you pass your body object instead of a token?

jhyoo2 commented 2 years ago

I try few things and In the end, the transaction was successful, but the function to load the friend list still does not work.

The modified sdk code is as follows.

 //modified;
Client.prototype.importFacebookFriends = function (token, reset) {
  return (
    this.apiClient
      //modified;
      .importFacebookFriends({ token: token, vars: null }, reset, {})
      .then(function (response) {
        console.log(response);
        return response !== undefined;
      })
  );
};

If I do this, the transaction is completed without a 401 or 400 error like the last time. There is a friend of mine who I checked through the FB API now, but that person is not being input to the NAKAMA server.


There seems to be a problem with the friend list sync process. During authentication, I found the following phenomenon:

  1. Works Client.authenticateFacebook(accessToken, true, "username", false)

  2. Makes Error Client.authenticateFacebook(accessToken, true, "username", true)

If you set the Sync Option to true like this, an error occurs. I know this is also a friend list sync feature, right? There seems to be some problem between the api and the current sdk.

jhyoo2 commented 2 years ago

The code I just posted is working. I just checked Your friend list is syncing. :)