I want to implement express checkout link with 2CO payment gateway ; tested the following code:
public void testExpressCheckoutF()
{
Twocheckout.apiusername = "sonoratestw";
Twocheckout.apipassword = "sonorasonora";
Twocheckout.privatekey = "81DBF3R3-04B3-47DB-8068-ED3DAB20BC5A";
Twocheckout.mode = "sandbox";
HashMap<String, String> params = new HashMap<>();
params.put("sid", "901328163");
params.put("mode", "sandbox");
params.put("currency_code", "USD");
params.put("x_receipt_link_url", "http://www.test.com/summary_twocheckoutl_payment.xhtml");
params.put("comment", "some description");
params.put("li_0_product_id", "assdsdcas");
params.put("li_0_type", "product");
params.put("li_0_name", "test name");
params.put("li_0_quantity", String.valueOf(1));
params.put("li_0_price", String.valueOf(33));
params.put("li_0_description", "some description");
String expressCheckout = TwocheckoutCharge.url(params);
System.out.println("\n " + expressCheckout);
}
But when I run the code I always get ERROR CODE:PE104. I found this post as a possible solution http://help.2checkout.com/articles/Knowledge_Article/Error-Code-PE104/?l=en_US&fs=RelatedArticle
But still getting the same error. Can you propose some solution?
Please try removing the li_0_product_id param and trying again or changing the value to an integer and not a string. The article you linked to gives you general areas to start (no lineitems, invalid product_id, etc..) so it's just process of elimination at this point.
Related
Similar to: I cannot query my dynamodb table from aws lambda due to wrong filterexpression? and DynamoDB update error Invalid UpdateExpression: An expression attribute value used in expression is not defined
I am trying to code a way to query DynamoDB tables using partial matches on Partition Key / Sort Key in Java.
The DynamoDB table I am trying to access has a Partition key of "Type" (A restricted key word in DynamoDB, I know, but not my choice) and a Sort key of "Id". I know the "Type" but not the full Id, so I have researched the Query method using AWS SDK 2.x source code and have implemented as shown below:
DynamoDBClient dynamoDbClient = DynamoDbClient.builder()
.region(Region.EU_WEST_1)
.credentialsProvider(StaticCredentialsProvider.create(awsCredentials))
.build();
String idKey = "wholeIdKey";
String idValue = "partialIdValue";
String typeValue = "typeValue";
Map<String, String> expressionNames = new HashMap<>();
expressionNames.put("#t", "Type");
QueryRequest request = QueryRequest.builder()
.tableName(tableName)
.keyConditionExpression("begins_with ( " + idKey + ", :" + idValue + " )
AND #t = :" + typeValue)
.expressionAttributeNames(expressionNames)
.build();
QueryResponse response = dynamoDbClient.query(request);
However, when I run this code, I get the following error message:
Exception in thread "main" software.amazon.awssdk.services.dynamodb.model.DynamoDbException:
Invalid KeyConditionExpression: An expression attribute value used in expression is not defined; attribute value: :typeValue
It's as if it's not recognizing the fact that I have told the code use the Expression Attribute Names feature to replace the "#t" with "Type" (Which is a reserved keyword in DynamoDB)
Can anyone help?
EDIT: References for code:
https://docs.aws.amazon.com/code-samples/latest/catalog/javav2-dynamodb-src-main-java-com-example-dynamodb-Query.java.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html
https://www.javadoc.io/static/software.amazon.awssdk/dynamodb/2.7.14/software/amazon/awssdk/services/dynamodb/model/QueryRequest.html#expressionAttributeNames--
The name is fine, but you're prefixing both values with ':'. That causes a lookup in ExpressionAttributeValues, which you did not provide.
Never try to write dynamic values directly into the query string.
Your expressionAttributeName looks fine, but you forgot to provide a value for :typeValue so dynamoDB cannot know what to look for.
In addition to what you did, you need to add an expressionAttributeValue where you can provide proper values. See documentation here
Fixed Code for whoever wants it in the future (Thanks to #aherve and #MattTimmermans)
DynamoDBClient dynamoDbClient = DynamoDbClient.builder()
.region(Region.EU_WEST_1)
.credentialsProvider(StaticCredentialsProvider.create(awsCredentials))
.build();
String idKey = "wholeIdKey";
String idValue = "partialIdValue";
String typeValue = "typeValue";
String typeKey = "typeKey";
Map<String, String> expressionNames = new HashMap<>();
expressionNames.put("#t", "Type");
expressionNames.put("#i", "Id");
Map<String, AttributeValue> expressionValues = new HashMap<>();
expressionValues.put(":typeName", AttributeValue.builder().s(typeValue).build());
expressionValues.put(":idName", AttributeValue.builder().s(idValue).build());
QueryRequest request = QueryRequest.builder()
.tableName(tableName)
.keyConditionExpression("#t = :typeName AND begins_with ( #i, :idName )")
.expressionAttributeNames(expressionNames)
.expressionAttributeValues(expressionValues)
.build();
response = dynamoDbClient.query(request);
I am using Jumblr(Tumblr API for Java) in my app to get all the dashboard posts from Tumblr. But I get only 20 posts in return. I want to increase the limit. I have looked into the Jumblr documentation
Kindly help me with this.
My code is below:
JumblrClient client = new JumblrClient(consumer_key, consumer_secret);
client.setToken(OAuthToken, OAuthSecretToken);
// Write the user's name
List<Post> posts = client.userDashboard();
System.out.print("\t"+posts.toString());
for (int i = 0; i<posts.size();i++) {
System.out.println("\t" + posts.get(i).getBlogName());
System.out.println("\t" + posts.get(i).getType());
System.out.println("\t" + posts.get(i).getPostUrl());
}
I found the solution to my problem in the Jumblr docs. I have to pass the options parameter to userDashboard().
Map<String, Integer> options = new HashMap<String, Integer>();
options.put("limit", 50);
List<Post> posts = client.userDashboard(options);
while trying to create a new bug in bugzilla, i am getting an error
"You must log in before using this part of Bugzilla"
Code looks like
`HttpClient httpClient = new HttpClient();
XmlRpcClient rpcClient = new XmlRpcClient();
XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(rpcClient);
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
factory.setHttpClient(httpClient);
rpcClient.setTransportFactory(factory);
config.setServerURL(new URL("http://192.168.0.203/xmlrpc.cgi"));
rpcClient.setConfig(config);
// map of the login data
Map<String, String> loginMap = new HashMap<String, String>();
loginMap.put("login", "bugzilla.admin#abcd.com");
loginMap.put("password", "bugzilla#admin");
loginMap.put("rememberlogin", "Bugzilla_remember");
// login to bugzilla
Object loginResult = rpcClient.execute("User.login", new Object[]{loginMap});
System.err.println ("loginResult=" + loginResult);
// map of the bug data
Map<String, String> bugMap = new HashMap<String, String>();
bugMap.put("product", "Demo");
bugMap.put("component", "Demo_project");
bugMap.put("summary", "Bug created for test");
bugMap.put("description", "This is text ");
bugMap.put("version", "unspecified");
bugMap.put("op_sys", "Windows");
bugMap.put("platform", "PC");
bugMap.put("priority", "P2");
bugMap.put("severity", "Normal");
bugMap.put("status", "NEW");
// create bug
Object createResult = rpcClient.execute("Bug.create", new Object[]{bugMap});
System.err.println("createResult = " + createResult);
`
At first i am able to login and the response I get is-: loginResult={id=1, token=1-AJ4uG13zlJ}
but when creating a new bug error occurs
`Exception in thread "main" org.apache.xmlrpc.XmlRpcException: You must log in before using this part of Bugzilla.
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
at com.abcd.BugCreator2.main(BugCreator2.java:52)`
Why do I get this error of login again, when I am already logged in.
Edit-:
The above code works fine when tried on https://bugzilla.mozilla.org
It seems there is some problem while configuration of Bugzilla on local server.
first of all thanks to you i was searching code just like yours...
and if you still get that error you should know that you also need to send login and password parameters for create method.
just try like this ..
add this
bugMap.put("login", "bugzilla.admin#abcd.com");
bugMap.put("password", "bugzilla#admin");
before this
bugMap.put("product", "Demo");
bugMap.put("component", "Demo_project");
bugMap.put("summary", "Bug created for test");
bugMap.put("description", "This is text ");
bugMap.put("version", "unspecified");
bugMap.put("op_sys", "Windows");
bugMap.put("platform", "PC");
bugMap.put("priority", "P2");
bugMap.put("severity", "Normal");
bugMap.put("status", "NEW");
I am trying to run Bing search API. I used odata4j and tried the code provided here:
How to use Bing search api in Java
ODataConsumer c = ODataConsumers
.newBuilder("https://api.datamarket.azure.com/Bing/Search")
.setClientBehaviors(OClientBehaviors.basicAuth("accountKey", "{your account key here}"))
.build();
OQueryRequest<OEntity> oRequest = c.getEntities("Web")
.custom("Query", "stackoverflow bing api");
Enumerable<OEntity> entities = oRequest.execute();
After I registered in the bing service, I obtained the key and placed it inside the double quotation in the above code. I got the following error:
Exception in thread "main" java.lang.RuntimeException: Expected status OK, found Bad Request. Server response:
Parameter: Query is not of type String
at org.odata4j.jersey.consumer.ODataJerseyClient.doRequest(ODataJerseyClient.java:165)
at org.odata4j.consumer.AbstractODataClient.getEntities(AbstractODataClient.java:69)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.doRequest(ConsumerQueryEntitiesRequest.java:59)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.getEntries(ConsumerQueryEntitiesRequest.java:50)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.execute(ConsumerQueryEntitiesRequest.java:40)
at BingAPI.main(BingAPI.java:20)
Caused by: org.odata4j.exceptions.UnsupportedMediaTypeException: Unknown content type text/plain;charset=utf-8
at org.odata4j.format.FormatParserFactory.getParser(FormatParserFactory.java:78)
at org.odata4j.jersey.consumer.ODataJerseyClient.doRequest(ODataJerseyClient.java:161)
... 5 more
I could not figure out the problem.
All what you need is to set your query like that %27stackoverflow bing api%27
Here is my source code:
ODataConsumer consumer = ODataConsumers
.newBuilder("https://api.datamarket.azure.com/Bing/Search/v1/")
.setClientBehaviors(
OClientBehaviors.basicAuth("accountKey",
"{My Account ID}"))
.build();
System.out.println(consumer.getServiceRootUri() + consumer.toString());
OQueryRequest<OEntity> oQueryRequest = consumer.getEntities("Web")
.custom("Query", "%27stackoverflow%27");
System.out.println("oRequest : " + oQueryRequest);
Enumerable<OEntity> entities = oQueryRequest.execute();
System.out.println(entities.elementAt(0));
You can further try different queries with different filters by keep adding name-value pairs by using .custom("Type of parameter","parameter") of the oQueryrequest object.Say you want to search for indian food but you want only small square images.
ODataConsumer consumer = ODataConsumers
.newBuilder("https://api.datamarket.azure.com/Bing/Search/v1/")
.setClientBehaviors(
OClientBehaviors.basicAuth("accountKey",
"YOUR ACCOUNT KEY"))
.build();
System.out.println(consumer.getServiceRootUri() + consumer.toString());
OQueryRequest<OEntity> oQueryRequest = consumer.getEntities("Image")
.custom("Query", "%27indian food%27");
oQueryRequest.custom("Adult", "%27Moderate%27");
oQueryRequest.custom("ImageFilters", "%27Size:Small+Aspect:Square%27");
System.out.println("oRequest : " + oQueryRequest);
Enumerable<OEntity> entities = oQueryRequest.execute();
int count = 0;
Iterator<OEntity> iter = entities.iterator();
System.out.println(iter.next());
I tried to look everywhere to find a solution for my problem without any success. I'm trying to login to http://www.dailystrength.org/ website, however, my code doesn't work properly since I'm seeing that my crawler can't access some users' profiles that are private for non-registered members.
Here is my code:
String loginUrl = source + "/index.php?option=com_comprofiler&task=login";
Document login = Jsoup.connect(loginUrl).timeout(20000).get();
Map<String, String> parameters = new HashMap<String, String>();
Elements inputs = login.select("input");
for(Element input : inputs)
{
parameters.put(input.attr("name"), input.attr("value"));
}
parameters.put("username", "user");
parameters.put("passwd", "pass");
parameters.put("remember", "yes");
cookies = Jsoup.connect(loginUrl).data(parameters).method(org.jsoup
.Connection.Method.POST).timeout(20000).execute().cookies();
I tried also to include hidden input values, but it didn't work too. Any help would be much appreciated.
Thank you
Hey you can use Htmlunit and jsoup. For login use Htmlunit, its easy, you just need to submit form with username and password, after login, new page will come and you can deal with jsoup with that new page.
Is this what u were trying to do
String loginUrl = "http://www.dailystrength.org/" + "/index.php?option=com_comprofiler&task=login";
Document login = Jsoup.connect(loginUrl).timeout(20000).header("username", "user").header("passwd", "pass").header("remember", "yes").post();
Map<String, String> parameters = new HashMap<String, String>();
Elements inputs = login.select("input");
for(Element input : inputs)
{
String thi= input.attr("name");
String thi2=input.attr("value");
System.out.println("THIS" + thi);
System.out.println("THIS2" + thi2);
parameters.put(input.attr("name"), input.attr("value"));
}
Hope this works for u