Get normal google image search results in google custom search API - android

I want my app to give sample images based on what the user typed.
I created a custom search engine, already ticked "search entire web but emphasise...", and ticked "Image Search".
Created an html GET request as per Google's instructions.
String start = "start=0";
// looking for
String strNoSpaces = toSearchIn.replace(" ", "+");
String url2 = "https://www.googleapis.com/customsearch/v1?"
+ "key=" + keyBrowser
+ "&cx=" + cx
+ "&q=" + strNoSpaces
+ start
+ "&searchtype=image"
+ "&alt=json";
return url2;
and it all works well, I retrieve the image URLs and inflate the grid view.
The problem is the quality of results. It is nowhere near the relevance of what you see on the main google.com search results, and it was kind of my goal. The results that I am getting are rather disappointing and make the whole feature not worth it.
For comparison
my "party" results
Normal search results
Can this be changed with some parameters? I already tried most of them without much difference

Related

How to open a URL with POST parameters via external browser in android [duplicate]

In my Android application, I need to open a link in Browser. This page can receive some data just via POST. Could I add these parameters (data) to the intent which start the browser?
Do you know if this is possible? If it is, could you give my a hint?
Use a webview:
WebView webview = new WebView(this);
setContentView(webview);
byte[] post = EncodingUtils.getBytes("postvariable=value&nextvar=value2", "BASE64");
webview.postUrl("http://www.geenie.nl/AnHeli/mobile/ranking/demo/index.php", post);
Intents sent to the browser can contain more than just a URL. In older versions of android it was possible to package extra POST data in the intent, in newer versions that capability is gone but one can send extra header data for a GET (which can be just about anything representable as a string) in the intent delivered to the browser.
try{
String finalUrl = "javascript:" +
"var to = 'http://the_link_you_want_to_open';" +
"var p = {param1:'"+your_param+"',param2:'"+your_param+"'};" +
"var myForm = document.createElement('form');" +
"myForm.method='post' ;" +
"myForm.action = to;" +
"for (var k in p) {" +
"var myInput = document.createElement('input') ;" +
"myInput.setAttribute('type', 'text');" +
"myInput.setAttribute('name', k) ;" +
"myInput.setAttribute('value', p[k]);" +
"myForm.appendChild(myInput) ;" +
"}" +
"document.body.appendChild(myForm) ;" +
"myForm.submit() ;" +
"document.body.removeChild(myForm) ;";
Uri uriUrl = Uri.parse(finalUrl);
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
PackageManager packageManager = this.getPackageManager();
browserIntent.setData(uriUrl);
List<ResolveInfo> list = packageManager.queryIntentActivities(browserIntent, 0);
for (ResolveInfo resolveInfo : list) {
String activityName = resolveInfo.activityInfo.name;
if (activityName.contains("BrowserActivity")) {
browserIntent =
packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
ComponentName comp =
new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
browserIntent.setAction(Intent.ACTION_VIEW);
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
browserIntent.setComponent(comp);
browserIntent.setData(uriUrl);
}
}
this.startActivity(browserIntent);
}catch (Exception e){
e.printStackTrace();
txtHeader.setText(e.toString());
}
I believe that there is a little misconception in the question. What is missing is the purpose that you need of the POST instead of GET.
If you admit I will make few assumptions that could be common in this context:
You need to hide the actual variables from history
You Need some interaction with server before user gets control
You cannot control the server itself and it uses (on purpose) POST requests
Any of those options or requirements implies some additional processing that is distinct from usual browser use case (which is to give full control over the processing and interaction). It seems that you are actually asking for Machine to Machine (M2M) communication with eventual HTML output.
If that renders to be true, then using some OKHttp, HTTPURLConnection, Apache HTTP Client, etc. is the right choice. Rather then invoking the browser via Intent, that has close to zero messaging capabilities (just fire and forget - in case of http:...). It actually requires some analysis of the data flow (sequence diagram might help) and then engineering of that process into M2M or assisted M2M interaction.
If the server you are using to interact with is your own, then why you do not create some REST/JSON/SOAP or other M2M API to make remote method calls (RPC/RMI/...). It is not that complex as it might look (e.g.: http://coreymaynard.com/blog/creating-a-restful-api-with-php/ or https://docs.phalconphp.com/pt/latest/reference/tutorial-rest.html)
Alternative would be to make your M2M interaction rather on your APP server, because then the eventual changes to the BE server data flow could be reflected without app change. By this you would be actually shifting the M2M communication partially to server side.
Note: Using application to interact with 3rd party servers might have some legal implications. In fact those server might not allow other use than through browser (human detection = captcha, User-Agent detection). In such case you have to negotiate with the server owner.

How to fill fields in a webview gettings data from remote URL

I am new developer in Android, I would to like to fill fields in a web view getting page from remote URL.
My application used shared preferences to store username/password to fill automatically fields username/password belongs to a login page. This login page is retrieved from a remote url and dispayed in webview.
How to fill the fields username/password?
Any suggestion can help me.
I already used javascript and does not work.
Regards
Try this one
webView.loadUrl("javascript: {" +
"document.getElementById('username').value = '"+username +"';" +
"document.getElementById('password').value = '"+password+"';" +
"var frms = document.getElementsByName('loginForm');};");

Get Larger Image From Facebook Post?

I'm currently getting the newsfeed of a Facebook user. Currently, I can only retrieve thumbnail images that are associated with links, rather than the full-size image. Does anyone know how to get a larger image?
I've looked at the following posts and tried their solutions; however, the posts seem outdated and the facebook graph api seems to have changed since then:
Facebook Graph API Change: Picture type (size) no longer working?
Facebook API post: How to get larger thumbnail?
Please note that I'm on the me/home edge, so the answer below returns an error. See comments below.
my code is:
params.putString("fields","id,actions,application,caption,created_time,description,from,link,message,message_tags,"
+ "name,object_id,picture,place,source,status_type,story,updated_time,type,status_type,story,to,type,"
+ "updated_time,with_tags");
Change to this:
params.putString("fields","id,actions,application,caption,created_time,description,from,link,message,message_tags,"
+ "name,object_id,full_picture,place,source,status_type,story,updated_time,type,status_type,story,to,type,"
+ "updated_time,with_tags");
Here picture.height(1000) will give you a large image. and you can put your own required size but it is not supported in me/home i have searched a lot.
For Testing purposre use this link :Facebook graph explorer.
Eventually I came to this solution:
1) find the URL of the larger image (see code below)
2) get bitmap from URL and add to application UI.
The code mentioned above:
private String getRealURL(String smallURL){
if (smallURL.contains("url=http")){
String[] pieces = smallURL.split("url=");
pieces[1].replace("%2F", "//");
pieces[1].replace("%3A", ":");
Log.e("RealURL1:", pieces[1]);
return pieces[1];
}
else{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.setLength(0);
stringBuilder.append("https://graph.facebook.com/");
stringBuilder.append(item.getObjectID());
stringBuilder.append("/picture?type=normal&access_token=");
stringBuilder.append(Session.getActiveSession().getAccessToken());
Log.e("RealURL2:", stringBuilder.toString());
return stringBuilder.toString();
}
}
Simply use this field ?field=full_picture instead of picture.
?field=full_picture is the only way to get it to work now. I have been searching everywhere, and finally found the answer here. picture field doesn't support subfields any more so you can't use picture.width.height any more

How can I upload multiple photos in one post on Google+ from G+ Android SDK?

I want to know how to upload multiple photos at a time thru google plus?
I found how to upload one photo and one message at a time from google plus sample code.
String action = "/?view=true";
Uri callToActionUrl = Uri.parse(getString(R.string.plus_example_deep_link_url) + action);
String callToActionDeepLinkId = getString(R.string.plus_example_deep_link_id) + action;
// Create an interactive post builder.
builder = new PlusShare.Builder(this, plusClient);
// Set call-to-action metadata.
builder.addCallToAction(LABEL_VIEW_ITEM, callToActionUrl, callToActionDeepLinkId);
// Set the target url (for desktop use).
builder.setContentUrl(Uri.parse(getString(R.string.plus_example_deep_link_url)));
// Set the target deep-link ID (for mobile use).
builder.setContentDeepLinkId(getString(R.string.plus_example_deep_link_id),
null, null, null);
// Set the message.
builder.setText("user message");
// Set the image
Uri uri = Uri.fromFile(new File("[user file path]"));
builder.setStream(uri);
Anyone knows about uploading multiple photos like facebook and twitter?
It should work with addStream() method, unfortunately... it doesn't work. Indeed it makes the application crash.
After a long search, I finally got it: it's not possible if using the simplified G+ SDK! (the one dedicated to Android).
There is a second one, included in the Google API family that you can find there:
http://code.google.com/p/google-api-java-client/wiki/APIs#Google+_API
This one will let you build more advanced post, included, several pic one.
Unfortunately the second SDK is much more low level, not dedicated to Android, it's a kind of Java abstraction over http request.
Regards

How can I open Android browser with specified POST parameters?

In my Android application, I need to open a link in Browser. This page can receive some data just via POST. Could I add these parameters (data) to the intent which start the browser?
Do you know if this is possible? If it is, could you give my a hint?
Use a webview:
WebView webview = new WebView(this);
setContentView(webview);
byte[] post = EncodingUtils.getBytes("postvariable=value&nextvar=value2", "BASE64");
webview.postUrl("http://www.geenie.nl/AnHeli/mobile/ranking/demo/index.php", post);
Intents sent to the browser can contain more than just a URL. In older versions of android it was possible to package extra POST data in the intent, in newer versions that capability is gone but one can send extra header data for a GET (which can be just about anything representable as a string) in the intent delivered to the browser.
try{
String finalUrl = "javascript:" +
"var to = 'http://the_link_you_want_to_open';" +
"var p = {param1:'"+your_param+"',param2:'"+your_param+"'};" +
"var myForm = document.createElement('form');" +
"myForm.method='post' ;" +
"myForm.action = to;" +
"for (var k in p) {" +
"var myInput = document.createElement('input') ;" +
"myInput.setAttribute('type', 'text');" +
"myInput.setAttribute('name', k) ;" +
"myInput.setAttribute('value', p[k]);" +
"myForm.appendChild(myInput) ;" +
"}" +
"document.body.appendChild(myForm) ;" +
"myForm.submit() ;" +
"document.body.removeChild(myForm) ;";
Uri uriUrl = Uri.parse(finalUrl);
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
PackageManager packageManager = this.getPackageManager();
browserIntent.setData(uriUrl);
List<ResolveInfo> list = packageManager.queryIntentActivities(browserIntent, 0);
for (ResolveInfo resolveInfo : list) {
String activityName = resolveInfo.activityInfo.name;
if (activityName.contains("BrowserActivity")) {
browserIntent =
packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
ComponentName comp =
new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
browserIntent.setAction(Intent.ACTION_VIEW);
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
browserIntent.setComponent(comp);
browserIntent.setData(uriUrl);
}
}
this.startActivity(browserIntent);
}catch (Exception e){
e.printStackTrace();
txtHeader.setText(e.toString());
}
I believe that there is a little misconception in the question. What is missing is the purpose that you need of the POST instead of GET.
If you admit I will make few assumptions that could be common in this context:
You need to hide the actual variables from history
You Need some interaction with server before user gets control
You cannot control the server itself and it uses (on purpose) POST requests
Any of those options or requirements implies some additional processing that is distinct from usual browser use case (which is to give full control over the processing and interaction). It seems that you are actually asking for Machine to Machine (M2M) communication with eventual HTML output.
If that renders to be true, then using some OKHttp, HTTPURLConnection, Apache HTTP Client, etc. is the right choice. Rather then invoking the browser via Intent, that has close to zero messaging capabilities (just fire and forget - in case of http:...). It actually requires some analysis of the data flow (sequence diagram might help) and then engineering of that process into M2M or assisted M2M interaction.
If the server you are using to interact with is your own, then why you do not create some REST/JSON/SOAP or other M2M API to make remote method calls (RPC/RMI/...). It is not that complex as it might look (e.g.: http://coreymaynard.com/blog/creating-a-restful-api-with-php/ or https://docs.phalconphp.com/pt/latest/reference/tutorial-rest.html)
Alternative would be to make your M2M interaction rather on your APP server, because then the eventual changes to the BE server data flow could be reflected without app change. By this you would be actually shifting the M2M communication partially to server side.
Note: Using application to interact with 3rd party servers might have some legal implications. In fact those server might not allow other use than through browser (human detection = captcha, User-Agent detection). In such case you have to negotiate with the server owner.

Categories

Resources