ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
125 stars 111 forks source link

ConnectyCube.pushnotifications.subscriptions.create(params) returns 401 error #131

Closed GuleriaAshish closed 3 years ago

GuleriaAshish commented 3 years ago

I am trying to integrate push notification with connetycube. But when i tried to hit ConnectyCube.pushnotifications.subscriptions.create(params) method with params that provided in documentation then it results a error code 401, {"code": 401, "info": {"errors": ["Token is required"]}}

code sample: Method decleration: const subcribeToPushNotification = (deviceToken) => { const DeviceInfo = require('react-native-device-info').default const params = { notification_channel: Platform.OS === 'ios' ? 'apns' : 'gcm', device: { platform: Platform.OS, udid: DeviceInfo.getUniqueId() }, push_token: { environment: 'development', client_identification_sequence: deviceToken, bundle_identifier: "com.afyanet" } } console.warn("param", params) // JS SDK v2+ ConnectyCube.pushnotifications.subscriptions.create(params) .then(result => { console.warn("suc", result) }) .catch(error => { console.warn("err", error) });

// JS SDK v1
/*
ConnectyCube.pushnotifications.subscriptions.create(
  params,
  (error, result) => {}
);
*/

}

Calling methods subcribeToPushNotification: // (optional) Called when Token is generated (iOS and Android) onRegister: function (token) {

            AsyncStorage.setItem('notification', token.token);
            const deviceToken = token.token;
            console.warn("token", deviceToken)
            subcribeToPushNotification(deviceToken);
        }, 
GuleriaAshish commented 3 years ago

Screenshot 2020-10-19 at 4 57 28 PM

GuleriaAshish commented 3 years ago

@ccvlad please suggest me what i am doing wrong .

ccvlad commented 3 years ago

Hi, @GuleriaAshish

I think you have not logged in to ConnectyCube. https://developers.connectycube.com/js/authentication-and-users?id=session-token-rights

GuleriaAshish commented 3 years ago

Hi, @GuleriaAshish

I think you have not logged in to ConnectyCube. https://developers.connectycube.com/js/authentication-and-users?id=session-token-rights

Thanks for the quick reply @ccvlad , really appreciate your efforts. I have logged in to connectycube successfully. And as i can see create subscription api require deviceToken which i have provided.

GuleriaAshish commented 3 years ago

@ccvlad any solution for this ? as i am still not able to figure it out.

ccvlad commented 3 years ago

Please provide a full log, from ConnectyCube.createSession to ConnectyCube.pushnotifications.subscriptions.create

GuleriaAshish commented 3 years ago

I am implementing notifications code in my app.js class. And in onRegister() method of notifications i am calling ConnectyCube.pushnotifications.subscriptions.create() this method with the token that i get from onRegister() method just like explained in your documentation.

I think there is no relation with connectycube session. That may take part when i am willing to send the notification but on subscription i don't think it is needed .

And the most important part is we can not createSession in app.js it must be created when we login .

ccvlad commented 3 years ago

Could you show your logs? You can not request to API w/o session

GuleriaAshish commented 3 years ago

[Response][1] {"session": {"application_id": 3448, "created_at": "2020-10-21T07:51:09Z", "id": 18537738, "nonce": 5077, "token": "65b09550bf95295b5b3074339054e1c976000d78", "ts": 1603266667, "updated_at": "2020-10-21T07:51:09Z", "user": {"avatar": "", "blob_id": null, "created_at": "2020-10-13T09:05:01Z", "custom_data": "", "email": null, "external_user_id": null, "facebook_id": null, "full_name": "Ashish Guleria", "id": 2190208, "last_request_at": "2020-10-21T07:51:09Z", "login": "Ashish", "phone": "9882744034", "twitter_id": null, "updated_at": "2020-10-21T07:51:09Z", "user_tags": null, "website": null}, "user_id": 2190208}} [Wed Oct 21 2020 13:21:09.358] LOG [Chat] Connect with parameters {"password": "Mind#123", "userId": 2190208} [Wed Oct 21 2020 13:21:09.358] LOG [Chat] status connecting wss://chat.connectycube.com:5291 [Wed Oct 21 2020 13:21:11.144] LOG [Chat] status connect [Wed Oct 21 2020 13:21:11.145] LOG [Chat] CONNECTING [Wed Oct 21 2020 13:21:11.146] LOG [Chat] status opening [Wed Oct 21 2020 13:21:11.146] LOG [Chat] SENT: [Wed Oct 21 2020 13:21:11.691] LOG [Chat] RECV: [Wed Oct 21 2020 13:21:11.692] LOG [Chat] status open [Wed Oct 21 2020 13:21:11.697] LOG [Chat] RECV: PLAINANONYMOUSPLAIN_FASTzlib</stream:features> [Wed Oct 21 2020 13:21:11.699] LOG [Chat] SENT: ADIxOTAyMDgtMzQ0OABNaW5kIzEyMw== [Wed Oct 21 2020 13:21:12.811] LOG [Chat] RECV: [Wed Oct 21 2020 13:21:12.812] LOG [Chat] status opening [Wed Oct 21 2020 13:21:12.813] LOG [Chat] SENT: [Wed Oct 21 2020 13:21:13.367] LOG [Chat] RECV: [Wed Oct 21 2020 13:21:13.367] LOG [Chat] status open [Wed Oct 21 2020 13:21:13.371] LOG [Chat] RECV: zlib</stream:features> [Wed Oct 21 2020 13:21:13.372] LOG [Chat] SENT: [Wed Oct 21 2020 13:21:13.918] LOG [Chat] RECV: jid>2190208-3448@chat.connectycube.com/1204607085-chat-68990</jid [Wed Oct 21 2020 13:21:13.919] LOG [Chat] SENT: [Wed Oct 21 2020 13:21:13.920] LOG [Chat] status online 2190208-3448@chat.connectycube.com/1204607085-chat-68990 [Wed Oct 21 2020 13:21:13.921] LOG [Chat] ONLINE [Wed Oct 21 2020 13:21:13.921] LOG [Chat] CONNECTED [Wed Oct 21 2020 13:21:13.922] LOG [Chat] SENT: [Wed Oct 21 2020 13:21:13.922] LOG [Chat] SENT: [Wed Oct 21 2020 13:21:14.470] LOG [Chat] RECV: [Wed Oct 21 2020 13:21:14.731] LOG [Chat] RECV: [Wed Oct 21 2020 13:21:14.734] LOG [Chat] RECV:

ccvlad commented 3 years ago

@GuleriaAshish

The log is not full.

Anyway, your steps should be:

ConnectyCube.init(appCreds, appConfig);

ConnectyCube.createSession(userParams).then(session => {
  ConnectyCube.pushnotifications.subscriptions.create(params);
});
GuleriaAshish commented 3 years ago

@ccvlad ,i am closing this issue as it's working now. Thanks for the help.