libspotify does not connect - connection

I'm trying to get familiar with libspotify and I must say the documentation on libspotify is seriously lacking. I've hacked together a small app from the examples but I can't get it to work.
I'm building a C Console Application in Visual Studio 2012. The appkey is correct.
sp_session_config config;
sp_error error;
sp_session *session;
char *blob = NULL;
memset(&config, 0, sizeof(config));
config.api_version = SPOTIFY_API_VERSION;
config.cache_location = "tmp";
config.settings_location = "tmp";
config.application_key = g_appkey;
config.application_key_size = g_appkey_size;
config.user_agent = "SpotiTest";
error = sp_session_create(&config, &session);
if (SP_ERROR_OK != error) {
fprintf(stderr, "failed to create session: %s\n",
sp_error_message(error));
return;
}
error = sp_session_login(session, "USERNAME", "PASSWORD", 1, blob);
if (SP_ERROR_OK != error) {
fprintf(stderr, "failed to log in to Spotify: %s\n",
sp_error_message(error));
sp_session_release(session);
exit(4);
}
sp_connectionstate cs = sp_session_connectionstate (session);
No matter what the username and password (false or correct) sp_session_login always returns SP_ERROR_OK. When I check the connection state with sp_session_connectionstate it always returns SP_CONNECTION_STATE_LOGGED_OUT.
I'm not seeing what I'm doing wrong here and also can't seem to find any relevant answers through the regular channels.

The API is asynchronous. sp_session_login returns immediately, and the login process continues in the background. Look at the examples that come with the API. You need some kind of event loop to call sp_session_process_events, or libspotify won't get any work done, and you probably want to wait until you receive the logged_in callback.

Related

e-MMC returns FR_OK at very first bring-up but mk_dir return FR_NO_FILESYSTEM

I am using stm32H753xx and Cube FatFs library.
After our e-MMC has been soldered to our board, I want to bring-up.
My startup codes is here:
res = f_mount(&fat_fs, "0:", 0);
if (res != FR_OK) {
res = f_mkfs("", FM_ANY, 0, work, sizeof(work));
if (res != FR_OK) {
while(1) {
LOGGER_REPORT(FORMAT_REQUEST_FAILED);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
res = f_mount(&fat_fs, "0:", 0);
if (res != FR_OK) {
while(1) {
LOGGER_REPORT(FORMATTED_BUT_NOT_MOUNTED);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
}
I generally expect an error at mounting phase if bringing-up of a memory device is very first time and this implies why I made my software branch to f_mkfs functions if f_mount fails. But f_mount is returning FR_OK and software is skipping here.
Afterwards, I am doing some api calls to detect latest directory in the root and to create new one by giving a name in way that would be latest+1. ( latest is like ./70/ new one ./71/ anyway)
There are some api calls here f_opendir, f_readdir, f_closedir respectively and all of them returns succesfully but,
whenever I want to create new dir by calling fs_mkdir, it returns FR_NO_FILESYTEM.
If I call f_mkfs after f_mount above, a FAT is creating and software works but I can not call f_mkfs ile that and could not figure it out where I have to put this code to make it run only once at very initial bring-up of e-MMC.

Checking response code of all URLs in a column [Airtable database]

We have an airtable database of over 24000 records. These records are websites, and many now have errors in them (missing "/", extra space...). We are trying to detect the websites that have these errors before manually fixing them.
What we have tried
So far, we have used the fetch method to call each URL and report back on the error status . This is the script we have used:
const inputConfig = input.config();
const url = inputConfig.url;
let status;
try {
const response = await fetch(url);
status = response.status; } catch (error) {
status = 'error'; }
output.set('status', status);
Issues we ran into
The script won't follow redirects, so it reports "error" back if there is a redirect even if the URL is working.
The output now is either "200" meaning the URL works, or "error". We don't get the actual response code of the error, which we ideally would like to get.
Any help would be appreciated! Thanks
There's some nuance to how fetch works. If you review Mozilla's documentation they say:
The Promise returned from fetch() won't reject on HTTP error status even if the response is an HTTP 404 or 500. Instead, as soon as the server responds with headers, the Promise will resolve normally (with the ok property of the response set to false if the response isn't in the range 200–299), and it will only reject on network failure or if anything prevented the request from completing.
So you have to do an extra check in your code to determine if the request was successful or not and throw your own error. In your case, you don't necessarily need to throw an error at all and can just rely on ok property of the response.
const config = input.config();
const url = config.url;
let status = null;
const response = await fetch(url);
if(response.ok) {
status = response.status
} else {
status = 'error'
}
output.set('status', status);

Gupshup - multiple messages delay feature not working

I've tried to implement a delay feature on my bot to display multiple messages one after the other. The delay feature is displaying in my Flow Bot Builder diagram, but when I test in the conversation tester, and proxy bot on Messenger, the delay doesn't actually happen - all the messages display at once.
I have added the delay code in the IDE to the default.scr file:
[main]
label_dych:Hi! I'm delay-bot and I'm here to help you with any questions you have.:continue
((delay 2000))
label_gthk:I'll never need to take any personal or financial information from you, so as we chat please don't tell me any!:continue
((delay 1000))
label_ylbn:{"name":"quickreply","type":"quick_reply","alias":"What can I help you with?","msgid":"117af569-5188-ff7e-9b48-8c553c2f36cb","content":{"type":"text","text":"What can I help you with?"},"options":[{"type":"text","title":"My Page","iconurl":"","id":"ac49ad32-c9bc-469f-2152-c7c842bad8ea","isDuplicate":false,"name":"user"},{"type":"text","title":"Team Spaces","iconurl":"","id":"8a2017ac-2fc3-0901-be8d-1fad5a2dba12","isDuplicate":false,"name":"user"},{"type":"text","title":"Offline Support","iconurl":"","id":"70861407-e706-17a3-207b-c43958fde83e","isDuplicate":false,"name":"user"},{"type":"text","title":"Something else","iconurl":"","id":"d3f7b6b4-e70a-098d-dde9-1da3e8cc08dc","isDuplicate":false,"name":"user"}]}
I've also added the options.apikey line of code to the index.js file as instructed to do here: https://www.gupshup.io/developer/docs/bot-platform/guide/sending-multiple-messages-botscript
function ScriptHandler(context, event){
var options = Object.assign({}, scr_config);
options.current_dir = __dirname;
//options.default_message = "Sorry Some Error Occurred.";
// You can add any start point by just mentioning the
<script_file_name>.<section_name>
// options.start_section = "default.main";
options.success = function(opm){
context.sendResponse(JSON.stringify(opm));
};
options.error = function(err) {
console.log(err.stack);
context.sendResponse(options.default_message);
};
botScriptExecutor.execute(options, event, context);
options.apikey = "1mbccef47ab24dacad3f99557cb35643";
}
Is there any obvious reason why the delay effect wouldn't be working in between messages? I've used the apikey that is displayed for my gupshup account when I click the logo in the top right.
You have placed the API key after the scripting tool execute function is called. Place the API Key anywhere before the botScriptExecutor.execute and the delay should work.
Also, the timing of the delay is in milliseconds.
Sample:
function ScriptHandler(context, event){
var options = Object.assign({}, scr_config);
options.current_dir = __dirname;
//options.default_message = "Sorry Some Error Occurred.";
options.apikey = "1mbccef47ab24dacad3f99557cb35643";
// You can add any start point by just mentioning the
<script_file_name>.<section_name>
// options.start_section = "default.main";
options.success = function(opm){
context.sendResponse(JSON.stringify(opm));
};
options.error = function(err) {
console.log(err.stack);
context.sendResponse(options.default_message);
};
botScriptExecutor.execute(options, event, context);
}

Unity3D iOS device token is always null

I am trying to get push notifications to work on iOS, but I can not get access to the device token!
My Unity version is 5.4.1f1.
I have enabled the Push Notifications capability in XCode and all the certificates are setup correctly:
In my script in the start method I call this:
UnityEngine.iOS.NotificationServices.RegisterForNotifications
(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge
| UnityEngine.iOS.NotificationType.Sound, true);
Then from the update method I call this method:
private bool RegisterTokenWithPlayfab( System.Action successCallback,
System.Action<PlayFabError> errorCallback )
{
byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
if(token != null)
{
// Registration on backend
}
else
{
string errorDescription = UnityEngine.iOS.NotificationServices.registrationError;
Debug.Log( "Push Notifications Registration failed with: " + errorDescription );
return false;
}
}
The token keeps being empty, so the else-branch is entered every call. Also, the registrationError keeps being empty.
Can someone point me in the right direction on this? What else can I try or how can I get more infos on what is going wrong??
Try this one
Go to your application target. Choose Capabilities and ensure that ‘Push Notifications’ is enabled there.
You need to check deviceToken in a Coroutine or Update.
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using NotificationServices = UnityEngine.iOS.NotificationServices;
using NotificationType = UnityEngine.iOS.NotificationType;
public class NotificationRegistrationExample : MonoBehaviour
{
bool tokenSent;
void Start()
{
tokenSent = false;
NotificationServices.RegisterForNotifications(
NotificationType.Alert |
NotificationType.Badge |
NotificationType.Sound, true);
}
void Update()
{
if (!tokenSent)
{
byte[] token = NotificationServices.deviceToken;
if (token != null)
{
// send token to a provider
string token = System.BitConverter.ToString(token).Replace('-', '%');
Debug.Log(token)
tokenSent = true;
}
}
}
}
The implementation is horrible, but we don't have callbacks from Unity side so we need to keep listening that variable value.
Check the documentation:
https://docs.unity3d.com/ScriptReference/iOS.NotificationServices.RegisterForNotifications.html
Also seems to need internet. I guess there is an Apple service going on there.
Yes, registration error is empty even when user deniy permissions.
What i did is to use UniRX and set an Observable fron a Coroutine with a time out so it dont keep forever asking for it.
If you accepted and you do not received the token might be the internet conection. And i guess you are teying this on a real device.

Close distant USSD session

I am working on a USSD client. Everything works fine except for closing a distant USSD session.
In the specification, we can see the function CUSD:
AT+CUSD=2 should close the USSD session, but this is not really the case.
In fact when I do this sequence:
AT+CUSD='#xxx#',12
AT+CUSD='1',12
I have an open distant connection.
On your handset, you can open a new session by dialing #xxx*#
If I send a:
AT+CUSD='#xxx*#',12
This is not opening a new distant session.
If I send a:
AT+CUSD=2
AT+CUSD='#xxx#'
This is not opening a new distant session.
Do you know how to close a distant session?
I am working with huwaei key E160 and E173 on windows or Linux.
Use in the following way.
AT+CUSD='#xxx#',15
AT+CUSD=2
I am posting this because this is the top result regarding terminating USSD sessions using AT commands and also because the answers are vague.
This is the c# code i used in the end(I was sending the commands to a gsm modem). Hope it helps someone else
SerialPort SendingPort=null;
public string TerminateUssdSession()
{
InitializePort();
//// generate terminate command for modem
string cmd = "";
cmd = "AT+CUSD=2\r";
// send cmd to modem
OpenPort();
SendingPort.Write(cmd);
Thread.Sleep(500);
string response = SendingPort.ReadExisting();
return response;
}
private void InitializePort()
{
if (SendingPort == null)
{
SendingPort = new SerialPort();
SendingPort.PortName = PortName;//put portname here e.g COM5
SendingPort.BaudRate = "112500";
SendingPort.Parity = Parity.None;
SendingPort.DataBits = 8;
SendingPort.StopBits = StopBits.One;
SendingPort.Handshake = Handshake.None;
SendingPort.ReadTimeout = 500;
}
}
private void OpenPort()
{
if (!SendingPort.IsOpen)
{
SendingPort.Open();
}
}

Resources