I've been able to retrieve everything but the contacts photo by following the API.
I can get the img url as well as the gd:etag from the xml returned. Below is the Google API example, and it is the same thing I get, with the value of the attributes being different of course for my contacts.
<link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*'
href='https://www.google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de'
gd:etag='"KTlcZWs1bCp7ImBBPV43VUV4LXEZCXERZAc."'>
The problem is I don't know how to get it to display. When I try it, I just get the last part of the url (ie: "/32432eewqdweq") and no image.
I'm using rails, and this is my second week of doing web development, sorry if I seem noobish aha.
Any help would be appreciated!
Thanks,
Goran
You would need to make a request to the url, but also include the access_token as a query parameter.
So, using your example, let's say if your access_token is ABCDEF123456ABCDEF, then the GET request you want to make is:
https://www.google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de?access_token=ABCDEF123456ABCDEF
Just a small hint, according to Google's API docs:
Note: If a contact does not have a photo, then the photo link element
has no gd:etag attribute.
More info here
First, you need to make a authorized GET to that url, i.e., in the Authorization header you have to put "OAuth " + AccessToken. Also, I haven't tried but, as Savil has said, with the Access Token as a Query Parameter, you can also achieve the same.
In any case, Google responds you with the bytes of the image, so you cannot display as is. You'll need either save the byte array to a file in your server (I don't think this to be a good solution) or find another way to display the photo
If you want to read more about it, here is Google's documentation about contact photos
This is a rather old question, but nevertheless I hope this can be helpful
Use the same authorized request code used for retrieving contacts and just replace the url with the link rel url of the contact image. Response will be the bytes of the image. Use the following code to return image as response.
//'in' is the inputStream returning from the call, response is the HttpServletResponse
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int read;
while (true) {
if ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
} else {
break;
}
}
response.setContentType("image/jpeg");
response.setContentLength(buffer.length);
request.getSession().setAttribute("image", new String(out.toByteArray()));
response.getOutputStream().write(buffer);
Related
Now I tried to make like a translator through Roblox Studio using Https service by sending a request to the translate.google.com link the thing is that anything I get in return does not give me the translated text.
I put what I received in a google doc and tried to find it by pressing ctrl + f to try to find it but no luck the only thing I could find is that text that was supposed to be translated. Here is the code in case you want to try it for yourself but I do warn you that running this might make Roblox unresponsive for a while since it is a lot of info they gave back.
I don't know if I am doing something wrong or not someone please help! I just want it to give me what 'Hello world' would be in french, there are also no error messages.
local http = game:GetService("HttpService")
local Message = "Hello world"
http:UrlEncode(Message) -- 'Hello world' -> 'Hello%20world'
local response = http:RequestAsync(
{
Url = "https://translate.google.com/?sl=en&tl=fr&text=" .. Message .. "!&op=translate";
Method = "GET"
}
)
if response.Success then
print(response.StatusMessage)
print(response.StatusCode)
print(response.Body)
--print(response.Headers)
else
print("The request failed: ", response.StatusCode, response.StatusMessage)
end
When visiting on your browser (for example) the url https://translate.google.com/?sl=en&tl=fr&text=Hello%20World!&op=translate, the translation you see is fetched using Javascript code executed by the browser after loading the page.
The browser retrieves the html body of the page (like you did in your code) and then executes the javascript in the html body which retrieves the translation and updates the page.
Unless you use a browser driver like Selenium I don't see how you can do what you want in a simple way.
Plus, I'm sure that Google has some protection against automatic bots, so after too many request your program will probably will be blocked by ReCaptcha.
The correct way to translate the text is to use the Google Cloud Translate API which I think is free up to 500k requests per month. There is also Azure Translator from Microsoft which also has a free tier.
Your issue is likely in how you are URL Encoding the string.
http:UrlEncode(Message)
HttpService.UrlEncode returns the encoded string as a new value. It doesn't mutate the existing value. So you just need to store the result of the function call.
Message = http:UrlEncode(Message)
EDIT : Just as #Mohamed AMAZIRH pointed out, hitting this URL will only return HTML.
I am working on integrating Parse with Unity for WebGL. Since the Parse plugin currently doesn't work with WebGL, I am forced to use the REST API (or edit the source code, which hasn't been working). Unfortunately, Parse doesn't have any documentation on how to use the REST API within the Unity/WebGL app, so I'm not even sure if I'm doing it right. Regardless, attempting to sign up with the code I posted below only gives me a "401 Unauthorized" error, at least in the Unity editor (I currently can't test to see if an actual build on my server will do anything different). I've also tried using the Client Key instead of the REST-API Key, but that had the same effect. Could someone give me pointers on where to go from here?
Here's my code:
string url = "https://api.parse.com/1/users";
WWWForm form = new WWWForm();
form.AddField("X-Parse-Application-Id", APP_ID);
form.AddField("X-Parse-REST-API-Key", REST_ID);
form.AddField("X-Parse-Revocable-Session", 1);
form.AddField("Content-Type", "application/json");
string newDataString = "{\"username\":\"" + email + "\",\"password\":\"" + password + "\",\"email\":\"" + email + "\"}";
WWW www = new WWW(url, System.Text.Encoding.UTF8.GetBytes(newDataString), form.headers);
The 401 error seems to point to a direction: the headers are not properly formatted. As an example, I was getting the same error because in the text field of an Authorization header there was a blank space between the = and " characters, like this:
token= "ajifidjoa...
So, first off, I suggest you to use something like Postman or any other REST client plugins for Chrome and test your call using them.
This way you should be able to understand better where the error is hidden.
Moreover, working with REST calls in Unity I found that a WebClient is way better for doing POST; sample code:
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/json";
result = client.UploadString(url, "POST", json_string_to_post);
}
I need to do CRUD on Custom Search Engines. From documentation, it looks pretty straight forward. I keep getting 401 responses though.
I am using Google.Apis.Oauth2.v2 to get a token:
String serviceAccountEmail = "blahblahblah#developer.gserviceaccount.com";
var certificate = new X509Certificate2(#"key.p12", "blah", X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { "https://www.googleapis.com/auth/cse" }
}.FromCertificate(certificate));
bool result = credential.RequestAccessTokenAsync(CancellationToken.None).Result;
TokenResponse token = credential.Token;
I then add the token to the following request (Authorization: Bearer mytoken):
GET http://cse.google.com/api/<USER_ID>/cse/<CSE_ID>
There are a few things that jump at me.
Exact quote from documentation:
Although you can set HTTP requests to the URL http://cse.google.com/api/[USER_ID]/cse/[CSE_ID], we recommend using
the following URL instead:
http://cse.google.com/api/[USER_ID]/cse/[CSE_ID]
Note that both URL's are exactly the same.
In authentication section, the sample is using ClientLogin, which is deprecated. No samples with OAuth 2.0.
In the document's example, it says:
Each Custom Search engine is identified by a unique ID created by
combining a user ID with a Custom Search engine ID, separated by a
colon, like this:
011737558837375720776:mbfrjmyam1g In this case, the user ID is
011737558837375720776, and the search engine ID is mbfrjmyam.
You would have noticed that the search engine ID is 2 characters short of what it looks like should be.
Nowhere I have seen the scope as "https://www.googleapis.com/auth/cse". I just copied it from a stackoverflow post.
I understand this is a very long question, but I hope this will help the next person to look at this and consider these points.
Anyone knows why the 401s?
I have the following code (please excuse the bad coding, it's like that to debug):
$postData = Mage::app()->getRequest()->getPost();
if(!$postData)
{
$postData = $this->getRequest()->getPost();
}
if(!$postData)
{
$postData = $_POST;
}
As you can see, I am simply trying to get the HTTP POST values.
Here's the scenario:
From a HTTP POST Simulator, the data comes through
From the Shopify webhook, nothing comes through (just "Array()")
Shopify posting to PostCatcher shows a lot of data
Shopify is posting in JSON format.
Any ideas as to ahy I can't catch the POST array?
You cant get JSON post values by using simply $_POST or Mage::app()->getRequest()->getPost();. Just try this,
$value = json_decode(file_get_contents('php://input'));
print_r($value);
In one of my project I got the same error
Mage::app()->getRequest()->getPost(); was giving the blank values.
I was using one extension when I was submitting the form there was one description field for the manufacturer.
If it was having text content like from , select or some content similar to SQL commands.
It was not posting the form data.
The reason was the hosting provider had some settings for sanitizing the data to prevent the SQL injection.
I raised the ticket to the hosting provider and the problem was solved.
Before this I tried lot of coding stuff which was not required.
Basically
Mage::app()->getRequest()->getPost(); and $this->getRequest()->getPost(); are the same if you are in a controller.
They are also the same thing with $_POST with some additional filtering on the values.
So if you receive an empty array in any case you should receive an empty array for all cases.
Make sure the data is sent through POST.
Also try to see how $this->getRequest()->getParams() look like. Maybe Magento considers that the parameters are sent through _GET
In the tutorial enter link description here they only show this:
var url = "http://api.twitter.com/1/statuses/public_timeline.json";
this.__store = new qx.data.store.Jsonp(url, null, "callback");
But I would need to communicate with my own server, so I've made some changes: (url and Jsonp to Json)
var url = "http://127.0.0.1:8000/";
this.__store = new qx.data.store.Json(url);
But I would need to be able to send some information to the server when the store make the request like:
{serviceToUseOnServer: 'articles', argument1: 'xxx'}
This is like a POST request, but I don't really know how to send that data to the server using qooxdoo's Store models. Please don't tell me to use GET and encode all that data in an url.
You got the possibility to configure the request object used to send the data. Just add a delegate to the store and implement the configureRequest method [1].
[1] http://demo.qooxdoo.org/current/apiviewer/#qx.data.store.IStoreDelegate~configureRequest