I'm working on a project which use the mediawiki API and I have this error :
error code=mustpostparams
info:'The following parameters were found in the query string, but must be in the POST body: lgpassword, lgtoken.'
This is my code :
Mediawiki wiki=new Mediawiki(site);
Login login=wiki.login(login,password); //error
wiki.edit(title, content , summary);
wiki.logout();
To login to my mediawiki I use login action but I think I can use query action.
In the documentation : https://www.mediawiki.org/wiki/API:Tokens I found :
PARAMS = {
'action':"query",
'meta':"tokens",
'type':"login",
'format':"json"
}
I think it's exactly what I need but it's in python and I don't know how to do this in Java. I know that there is a function getQueryResult() but I don't know how to use it.
How to do the query action in Java ?
Thanks
Like this post, both are related :
I just add
Mediawiki wiki=new Mediawiki(site);
wiki.setVersion("Mediawiki 1.28"); //New
Login login=wiki.login(login,password);
And don't forget to use a bot ! https://www.mediawiki.org/wiki/API:Login
Related
I'm trying to hit an API thru RestAssured + Java code and able to get some response as you can see in this post. But I need to get the value of particular node / attribute i.e. errorParams which is present in the JSON and print in the Java Console.
{
"customerId":null,
"errorDetails":[
[
{
"errorCode":"ABC_2021",
"errorParams":"Input Customer Id"
}
]
]
}
I tried like this and not working.
JsonPath jsp = new JsonPath(response.getBody().asString());
System.out.println(jsp.getString("errorDetails.errorParams"));
System.out.println(jsp.getString("$['errorDetails']['errorParams']"));
Any suggestions or working script would be helpful for me.
Thanks,
Karunagara Pandi G
That one works just fine:
System.out.println(jsp.getString("errorDetails.errorParams"));
So I assumed you retrieving your JsonPath in the wrong way, try:
JsonPath jsp = response.jsonPath();
or
JsonPath jsp = new JsonPath(response.asString());
you can use the following snippet it works for me
System.out.println(response.jsonPath().getString("errorDetails.errorParams"));
I have a domain name enrichment task.
I want to make a make a GNIP query using REST. Here's what I want to do:
Make a query to gnip containing a shortened url eg/"http ow.ly4eyW50fy4eP
Then use a gnip rule (maybe 'url_contains') to get the expanded url.
I am new to gnip, but I understand I can use the search api.
I'm having trouble finding a Java simple tutorial/'hello world' example for making gnip queries using rest :(
I found the rule 'url_contains' here:: http://support.gnip.com/apis/search_api/rules.html
And example REST requests here:
https://github.com/gnip/support/tree/master/Search%20API/Java
But nothing specifically on how to apply a gnip rule to a rest request.
I'm guessing the query might look like this (curl).
curl -X POST -u <me>
"https://search.gnip.com/accounts/me/search/prod.json -d '{
"rules": [
{
"value": "url_contains:bla"
}
]
}'
So my first question is, does this request look ok?
And if not, could anybody help me with an example? Or perhaps signpost me to an example online?
Ah! The answer is in the PostRequest.java class here ::
https://github.com/gnip/support/tree/master/Search%20API/Java
and no rule is required, the shortened url simply needs to be present in the payload as shown here::
http://support.gnip.com/enrichments/expanded_urls.html
I'm on a Java EE project and I need to use the value of a JS var on my Java code but my java code is execute before my JS (logic)
But I need the value of a JS var to execute my java and I think it will work if I execute my js on server-side but I don't know how to do this ...
My code is something like this :
JS :
function(){
var url = "an url of 20.000 char that I can't pass in GET and who is automatically generated by google chart API"
}
Java :
<%
String urlChart = "value of my "url" var in js";
session.setAttribute("urlChart", urlChart);
%>
But I don't know how tu put the value of my JS var un my java code. Can you help me ?
Somebody said me that I have to use AJAX but I don't know how to use it.
That is not possible in my understanding. you must switch to some other alternate solutions. you can use CGI or PHP or AJAX.
http://www.w3schools.com/ajax/
You can check this similiar question: how to send a string to a servlet from javascript using xmlhttprequest
If this won't help, then you need to provide more details because i'm not sure if i understand your problem.
I'd like to query a .cfm page via Android but I'm not sure what method I should be using to do so - any suggestions?
Example:
http://www.sheriff.org/apps/arrest/results.cfm?lname=smith&fname=
P.S.
Would I use something along the lines of this?
http://androidexample.com/AsyncroTask_Example_To_Get_Server_Data_-_Android_Example/index.php?view=article_discription&aid=59&aaid=84
use an ajax call with the url with the appropriate first and last name parameters, and then extract the result table from the return value.
see a working jsfiddle sample here: http://jsfiddle.net/FhHXK/
code:
$('#get').click(function () {
$.ajax({
url:'http://www.sheriff.org/apps/arrest/results.cfm?lname=a&fname=b',
type: 'GET'
}).done(function (data){
var result = $(data).find('table.datagrid');
console.log(result.html());
$('body').append(result);
});
});
I've found this guide on internet to publish on Wordpress using XML-RPC inside my Java Project, for example I want a message on my Blog, every time it's specified date.
http://wordpress.rintcius.nl/post/look-how-this-wordpress-post-got-created-from-java
Now, I've followed the guide and I'm trying to let it run but I don't understand yet how exactly parameters for my post works.
For example using the method blogger.NewPost I call:
public Integer post(String contents) throws XmlRpcException {
Object[] params = new Object[] {
blogInfo.getApiKey(),
blogInfo.getBlogId(),
blogInfo.getUserName(),
blogInfo.getPassword(),
contents,
postType.booleanValue()
};
return (Integer) client.execute(POST_METHOD_NAME, params);
}
and my "contents" value is:
[title]Look how this wordpress post got created from java![/title]"
+ "[category]6[/category]"
+ FileUtils.getContentsOfResource("rintcius/blog/post.txt");
(I'm using "[" instead of "<" and "]" instead of ">" that are processed by stackoverflow)
Now, how could I use all parameters in this XML way?
Parameters here: http://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newPost
And, it's the content only a "string" without any tag?
Thanks a lot to all!
Still don't know why it gives me back errors but i think it's only a bit outdated.
Found this other libraries that works perfectly
http://code.google.com/p/wordpress-java/
I advice all to use this since the other one is outdated
Thanks all