I'm using react for making a Spotify clone and I'm getting an error for user authentication that INVALID_CLIENT: Invalid redirect URI - spotify

I'm getting a error I'm using React.js
export const authEndpoint = "https://accounts.spotify.com/authorize";
const redirectUri = "http:/localhost:3000/";
const clientId ="XXXXXXXX";
const scopes = [
"user-read-currently-playing",
"user-read-recently-played",
"user-read-playback-state",
"user-top-read",
"user-modify-playback-state",
];
export const loginUrl = `${authEndpoint}?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scopes.join("%20")}&response_type=token&show_dialog=true`;

try look at the register url on Spotify dashbord, you have to set the same url on your aplication

Related

How to collect Instagram App Secret to generate a long-lived token?

On this page I generate the access token and with it I can publish the image on my Instagram:
For publish:
function InstagramPost() {
const access_token = 'GENERATE ACESS TOKEN';
const instagram_business_account = 'YYYYYYYYYYYYYYYYYY';
const image = 'https://upload.wikimedia.org/wikipedia/en/9/95/Test_image.jpg';
const text = 'Hello World';
var formData = {
'image_url': image,
'caption': text,
'access_token': access_token
};
var options = {
'method' : 'post',
'payload' : formData
};
const container = 'https://graph.facebook.com/v14.0/' + instagram_business_account + '/media';
const response = UrlFetchApp.fetch(container, options);
const creation = response.getContentText();
var data = JSON.parse(creation);
var creationId = data.id
var formDataPublish = {
'creation_id': creationId,
'access_token': access_token
};
var optionsPublish = {
'method' : 'post',
'payload' : formDataPublish
};
const sendinstagram = 'https://graph.facebook.com/v14.0/' + instagram_business_account + '/media_publish';
UrlFetchApp.fetch(sendinstagram, optionsPublish);
}
Now I want to take this access token and generate a long-lived one with it!
It asks for Instagram App Secret, but that path indicated (App Dashboard > Products > Instagram > Basic Display > Instagram App Secret) doesn't exist in App Dashboard!
I tried using the App secret as a parameter:
"https://graph.instagram.com/access_token
?grant_type=ig_exchange_token
&client_secret={App Secret Key}
&access_token={short-lived-access-token}"
But this error occurs:
Sorry, this content isn't available right now
The Facebook API is 100% accessible, so that's not the problem.
In Javascript/NodeJS I couldn't get it working at all (also on PostMan), I was using the request library.
Changed my code to:
const respLong = await axios.get(`https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_secret=${CLIENT_SECRET}&access_token=${accessTokenShort.toString()}`);
And magically this works. I can't tell you why what seems to be the exact same request in Postman and the request library doesn't work.
See pic of the url to get app secret (add your app ID) is: https://developers.facebook.com/apps/YOUR_APP_ID(number)/instagram-basic-display/basic-display/
There is a difference in approach between Basic Display and Instagram Graph API for Business Account.
So the way to convert a short-lived token to a long-lived token for Instagram Business Account is:
"https://graph.facebook.com/{graph-api-version}/oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={your-short-lived-access-token}"
Note that Instagram App Secret is not used, instead, use App Id and App Secret.

Get redirected data with nodejs

So I'm using node-myanimelist
npm package which is a wrapper for myanimelist API and the package uses pcke-challenge which provides a challenge (basically users go to a url, authorize and it redirects the user with an access token for me to use). Here's an image below to clear the idea
Once you click on allow, the user will be redirected to a URL that you specify with the access token. BUT here's the catch, my application does not have a website and I don't have a place to redirect the user to so what's the best approach to still get the token when the user clicks allow?
EDIT:
Here's the code:
const { Mal, Jikan } = require('node-myanimelist');
const auth = Mal.auth(/* app_id */);
const pkceChallenge = require("pkce-challenge");
const pkce = pkceChallenge();
// This is the URL the user gets
const url = auth.getOAuthUrl(pkce.code_challenge);
// "code" here is what clicking allow on the URL above ^ returns with the redirect
const acount = await auth.authorizeWithCode(code,pkce.code_challenge);
// From then on I can do stuff like `account.anime.search(/* stuff */)`

How authenticate with gcloud credentials an Dialogflow API

I have a Node JS app that make requests to a Dialogflow agent. I actually use a temporally token based request, but how can i change this to do it through google service credentials? (https://cloud.google.com/docs/authentication/getting-started). I have a credencial created (with billing added), and the service_account json file.
I would like to use the Dialogflow package in node (https://www.npmjs.com/package/dialogflow) but i don't underestand how to use it with the json file.
const projectId = 'ENTER_PROJECT_ID_HERE';
const sessionId = 'quickstart-session-id';
const query = 'hello';
const languageCode = 'en-US';
// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient();
// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
The example of the package use Project ID and Session ID, but not with a json file like the example of the google services (or using big query like How to authenticate with gcloud big query using a json credentials file?). Anyway, where can i get this project and session id?
Please, if someone can help me or guide how to do this in a better way?. Thanks
First you have to create a service account and download a .JSON format file of credentials on your local system.
Now, there are three ways to use that credentials for authentication/authorisation in dialogflow library.
Method 1
Create a environment variable GOOGLE_APPLICATION_CREDENTIALS and it's value should be the absolute path of that JSON credentials file.By this method, google library will implicitly loads the file and use that credentials for authentication. We don't need to do anything inside our code relating to this credentials file.
export GOOGLE_APPLICATION_CREDENTIALS="<absolute-path-of-json-file>" # for UNIX,LINUX
# then run your code, google library will pick credentials file and loads it automatically
Method 2
Assume, you know the absolute path of your JSON file and put that as value in below snippet of credentials_file_path variable.
// You can find your project ID in your Dialogflow agent settings
const projectId = '<project-id-here>';
const sessionId = '<put-chat-session-id-here>';
// const sessionid = 'fa2d5904-a751-40e0-a878-d622fa8d65d9'
const query = 'hi';
const languageCode = 'en-US';
const credentials_file_path = '<absolute-file-path-of-JSON-file>';
// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient({
projectId,
keyFilename: credentials_file_path,
});
Method 3
You can note down the project_id, client_email and private_key from the JSON, use them in your code for authentication explicitly.
// You can find your project ID in your Dialogflow agent settings
const projectId = '<project-id-here>';
const sessionId = '<put-chat-session-id-here>';
// const sessionid = 'fa2d5904-a751-40e0-a878-d622fa8d65d9'
const query = 'hi';
const languageCode = 'en-US';
const credentials = {
client_email: '<client-email-here>',
private_key:
'<private-key-here>',
};
// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient({
projectId,
credentials,
});
Here is how you can do it with a service account code sample is in kotlin and definitely can be translated into the node.js sdk
val credentialsProvider = FixedCredentialsProvider.create(ServiceAccountCredentials
.fromStream(Classes.getResourceAsStream([YOUR JSON CONFIG FILE GOES HERE])))
val sessionsSettings = SessionsSettings.newBuilder().setCredentialsProvider(credentialsProvider).build()
sessionsClient = SessionsClient.create(sessionsSettings)
You can get the service account from Dialogflow settings click on the service account links and then create a json config file there in ur cloud console.

The server was not able to find the TwiML application associated with the App SID

Twilio voice call got error "The server was not able to find the TwiML application associated with the App SID"
followed step
1 - create the twiml app in console
2 - generated api keys
3 - integrated with code
var identity = req.body.identity;
const voiceGrant = new VoiceGrant({
outgoingApplicationSid: config.twilio.twiml_voice_sid,
pushCredentialSid: config.twilio.PUSH_SID
});
const token = new AccessToken(config.twilio.accountSid, config.twilio.API_KEY, config.twilio.API_KEY_SECRET);
token.addGrant(voiceGrant);
token.identity = identity;
res.send({
identity: identity,
token: token.toJwt()
});
Token generated successfully but when I try to use that token from ios side
I got following error in ios sdk
Error: Error Domain=com.twilio.voice.error Code=21218 "Application not found." UserInfo={NSLocalizedDescription=Application not found., NSLocalizedFailureReason=The server was not able to find the TwiML application associated with the App SID}
Thanks in advance
Got the solutions... I forgot to add callback URL in TwiML app
I just created a POST URL in my app and added that URL in TWIML App
Here is the code for POST URL
exports.makeCall = function (req, res) {
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();
const dial = response.dial();
dial.client(req.body.To);
res.send(response.toString());
};

Docusign SOAP PHP API breaks with Fatal Error: Cannot redeclare class

I downloaded the DocuSign API and input my credentials, but when running an example, the API client dies because of class redeclarations.
It seems like the PHP API is just broken... but I see no similar questions about it on SO.
I commented out a bunch of declarations to get it to run. Has anyone else experienced this or know anything about it?
APIService.php
class EnvelopeEventStatusCode {
const Sent = 'Sent';
const Delivered = 'Delivered';
const Completed = 'Completed';
const Declined = 'Declined';
const Voided = 'Voided';
}
class EnvelopeEventStatusCode {
const Sent = 'Sent';
const Delivered = 'Delivered';
const Completed = 'Completed';
const Declined = 'Declined';
const AutoResponded = 'AutoResponded';
const AuthenticationFailed = 'AuthenticationFailed';
}
Don't use the code snippets. Do Use DocuSign Sample folder files instead and open Index.php to test it out.
It happens to me when I was developing.

Resources