Bad Authentication data on twitter api with http status 200 - javascript

I am using a twitter library in javascript called codebird-js. I provided my consumer key and token to tweet however I get back code 215 with the http status 200. On the twitter website it says that you usually get this code with http 400 so I dont know the meaning of this. This is the sample code, can anyone give me pointers on why I am getting this error:
<script type="text/javascript">
var cb = new Codebird;
cb.setConsumerKey('xxx','xxx');
cb.setToken('xxx', 'xxx');
var params = {
status: "im trying"
};
cb.__call(
"statuses_update",
params,
function (reply) {
console.log(reply);
});
</script>

215 means
Bad authentication data - Typically sent with 1.1 responses with HTTP code 400. The method requires authentication but it was not presented or was wholly invalid.
source : https://dev.twitter.com/overview/api/response-codes

Related

How to capture the headers of a 401 response or request with js o react?

How to capture the headers of a 401 response or request?
The server is returning this 401 to me since it needs a summary authentication, I need to create a hash to send it to the server from the MD5 algorithm, and I need to get the nonce from the 401 response to be able to calculate the MD5 algorithm, any ideas on how extract the headers the WWW-Authenticate nonce ? any ideas ?
I am using the JsSip.js library
work with react js or js
I leave the answer in an image that should censor some things
enter image description here
In order to retrieve the token from the header you should use Axios interceptors to and access it via req.headers,the proper header for a token is headers.authorisation:'Bearer tokenValue', docs
the same thing happens to me, I show you the configuration that I am using, can you tell me please if any information is missing? Since the 401 is not being answered automatically.
My code is:
var socket = new JsSIP.WebSocketInterface('wss://my.server.com/webrtc/')
var configuration = {
sockets: [socket],
uri: 'sip:TestUser#xxx.xx.xxx.xxx:5060',
password: 'xxxxxxx',
//contact_uri: 'sip:TestUser#xxx.xx.xxx.xxx',
}
var ua = new JsSIP.UA(configuration)
ua.start()
Thank you for your answer.

FastAPI rejecting POST request from javascript code but not from a 3rd party request application (insomnia)

When I use insomnia to send a post request I get a 200 code and everything works just fine, but when I send a fetch request through javascript, I get a 405 'method not allowed error', even though I've allowed post requests from the server side.
(Server side code uses python).
Server side code
from pydantic import BaseModel
from typing import Optional
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["POST", "GET"],
allow_headers=["*"],
)
class data_format(BaseModel):
comment_id : int
username : str
comment_body : Optional[str] = None
#app.post('/post/submit_post')
async def sumbit_post(somename_3: data_format):
comment_id = somename_3.comment_id
username = somename_3.username
comment_body = somename_3.comment_body
# add_table_data(comment_id, username, comment_body) //Unrelated code
return {
'Response': 'Submission received',
'Data' : somename_3
}
JS code
var payload = {
"comment_id" : 4,
"username" : "user4",
"comment_body": "comment_4"
};
fetch("/post/submit_post",
{
method: "POST",
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json'
}
})
.then(function(res){ return res.json(); })
.then(function(data){ alert( JSON.stringify( data ) ) })
The error
What should I do to get around this error?
Thanks in advance.
To start with, your code seems to be working just fine. The only part that had to be changed during testing it (locally) was the URL in fetch from /post/submit_post to (for instance) http://127.0.0.1:8000/post/submit_post, but I am assuming you already changed that using the domain name pointing to your app.
The 405 Method Not Allowed status code is not related to CORS. If POST was not included in the allow_methods list, the response status code would be 400 Bad Request (you could try removing it from the list to test it). From the reference above:
The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response
status code indicates that the server knows the request method, but
the target resource doesn't support this method.
The server must generate an Allow header field in a 405 status code
response. The field must contain a list of methods that the target
resource currently supports.
Thus, the 405 status code indicates that the POST request has been received and recognised by the server, but the server has rejected that specific HTTP method for that particular endpoint. Therefore, I would suggest you make sure that the decorator of the endpoint in the version you are running is defined as #app.post, as well as there is no other endpoint with the same path using #app.get. Additionally, make sure there is no any unintentional redirect happening inside the endpoint, as that would be another possible cause of that response status code. For future reference, when redirecting from a POST to GET request, the response status code has to change to 303, as shown here. Also, you could try allowing all HTTP methods with the wildcard * (i.e., allow_methods=['*']) and see how that works (even though it shouldn't be related to that). Lastly, this could also be related to the configurations of the hosting service you are running the application; thus, might be good to have a look into that as well.
It's and old issue, described here. You need Access-Control-Request-Method: POST header in your request.

Passing the value of JSON Object from HTTP Request to another JSON Object

I'm working on simple Chatbot in Line Messenger. I found some API which I want to use in the following way:
User sends specific key word like !send data. Then I send HTTP Request using request module. I'm getting the response and I output it in the console just to see if everything is correct. I'm parsing the repsonse with JSON.parse(body) and I'm able to access its specific values with
result = JSON.parse(body);
console.log(result.value.text);
Now I want to send result.value.text as a reply mesaage to the Line client.
Message has form
message = {
type: "text",
text: "someString"
}
But how can I pass the part of HTTP response to this object? Trying something like this
LINEResponse = {
type: "text",
text: result.value.text
};
leads to
UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
I'm not 100% sure if its even correct approach implement this. I would appreciate any help

CKEditor change in ajax URL ?t=timestam to ?open&t=timestamp

I use the CKEDITOR on my HTML page, but I can not connect it properly, my WEB server does not understand such requests and I need to change them.
My WEB server does not support requests like ?t=timestamp.
How can I change this, for example, to have ?Open&t=timestamp.
I have the following requests:
GET http://mysite.ru/webadmin/ckeditor/config.js?t=H4PG 400 (Bad Request)
GET http://mysite.ru/webadmin/ckeditor/skins/moono-lisa/editor.css?t=H4PG (Bad Request)
GET http://mysite.ru/webadmin/ckeditor/lang/ru.js?t=H4PG 400 (Bad Request)
Should be so
GET http://mysite.ru/webadmin/ckeditor/config.js?open&t=H4PG
GET http://mysite.ru/webadmin/ckeditor/skins/moono-lisa/editor.css?open&t=H4PG
GET http://mysite.ru/webadmin/ckeditor/lang/ru.js?open&t=H4PG
How to set my suffix for all connected plug-ins?
It seems to me that there is some parameter that will allow you to insert your HTTP command after the question.
Example,
CKEDITOR.config.<param>="open&"
or callback function
function(request){
request+="open&";
}
How to do it?
Tried it like this
function CKEDITOR_GETURL( resource ){
var base="/webadmin/ckeditor/";
var r=resource;
if(!/^\//.test(r))r=base+r;
return r;
}
But some of the resources are not properly processed, a bad idea

Axios API Twitter request not returning back user tweets

I am trying to call Twitters API and get a my tweets back so I can post them on a website I am creating.
When I run the following code I get an error.
XMLHttpRequest cannot load https://api.twitter.com/1.1/search/tweets.json?q=%SamSchaeferSays. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3333' is therefore not allowed access. The response had HTTP status code 400." And "bundle.js:30041 Uncaught (in promise) Error: Network Error.
I am new to API calls not using PHP - not sure what I am doing wrong here.
const tweet = 'https://api.twitter.com/1.1/search/tweets.json?q=%SamSchaeferSays';
function getUserTweet() {
return axios.get(`${tweet}`).then(function(response){
console.log(response.data)
console.log(response.status)
});
}
sample OAuth string
const DST = `OAuth oauth_consumer_key="${consumerKey}",
oauth_nonce="${}",
oauth_signature="${}",
oauth_signature_method="${}",
oauth_timestamp="${}",
oauth_token="${}",
oauth_version="1.0"
`;
A 400 Bad Request error means that the server doesn't understand your request. In your case there's a typo that prevents the request from going through (extra %). Try this:
const tweet = 'https://api.twitter.com/1.1/search/tweets.json?q=SamSchaeferSays';
function getUserTweet() {
return axios.get(`${tweet}`, { headers: { 'Authorization': 'YOUR_OAUTH_HEADER' } }).then(function(response){
console.log(response.data)
console.log(response.status)
});
}
This will fix the 400 Bad Request error, but you won't get any data back yet. The Twitter API requires you to authorize your request. Find out more in their documentation.
To allow applications to provide this information, Twitter’s API relies on the OAuth 1.0a protocol. At a very simplified level, Twitter’s implementation requires that requests needing authorization contain an additional HTTP Authorization header with enough information to answer the questions listed above. A version of the HTTP request shown above, modified to include this header, looks like this (normally the Authorization header would need to be on one line, but has been wrapped for legibility here):

Categories

Resources