I am trying to use the Twitter API with the following source code.
In “Cocos Creator v1.0.3”, I get the response as intended.
However, in “CocosCreator v1.1.0 to v1.6.0”, authentication failed and “” code “: 215,” message “:” Bad Authentication data. “” Is responded.
var xhr = cc.loader.getXMLHttpRequest();
xhr.open("GET", requestURL, true);
xhr.setRequestHeader("ContentType", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Authorization", authHeader);
xhr.onreadystatechange = function () {
console.log(xhr.responseText);
};
xhr.send();
The contents of “requestURL” and “authHeader” in the source code are correct. Because I sent by UnityWebRequest.Get () on Unity and got the correct response from “Twitter API”.
In “CocosCreator v1.1.0 to v1.6.0”, why authentication failed?
How can I improve my source code?
In the part of ******, necessary key / token is inputted respectively.
In Cocos Creator v1.0.3, I succeeded in searching tweets.
In Cocos Creator v1.1.0 to v1.6.0, I failed to search (authenticate).
The source code is the same.
Why is the result changed depending on the version difference?
I would like to use the Twitter API with the latest version of Cocos Creator.
I want to know if this phenomenon can be reproduced by other people.
It helps me to determine if the cause of this problem is in my environment or in Cocos Creator itself.
In the following version of Cocos Creator, I selected “Simulator” and executed it with “preview button”.
· “Mac version of Cocos Creator v1.0.3 or earlier” successfully searched tweets.
· “Windows version of Cocos Creator v1.5.1” successfully searched tweets.
· In “Mac version of Cocos Creator v1.1.0 to v1.6.0”, Twitter API authentication failed.
And in the Mac version of Cocos Creator v1.5.1, I built it for Native (Mac) and executed it, but the authentication failed as same as the simulator.
I ran “the source code written in the first post” in onload () of Hello World Project.
“authHeader” not be disclosed because it contains personal information.