To get an event from an Exchange calendar by ICalUId, you can use the FindItem-operation, using the UId base64-encoded as value to the Extended property identified by
DistinguishedPropertySetId=Meeting, PropertyId=3 and PropertyType=Binary.
This works great for events that are created in the Exchange calendar, where ICalUIds look like the following: 040000008200E00074C5B7101A82E00800000000A7C552582821D1010000000000000000100000002550ED442EB2CF4287FD94D10A4F331D
However, this does not work when trying to get the event with a Google Calendar UId, which looks like the following:
tp90m1srk847n1oa4jtp9ofou0#google.com
Not even using the substring before #google.com works, sadly.
Is there a way to get Google Events in the Exchange Calendar with EWS?
The GlobalObjectId is generated from the UID in this case using the formula defined in https://msdn.microsoft.com/en-us/library/ee157690(v=exchg.80).aspx . So if all you have is the UID you will need to generate the GlobalObjectId to search using your own algorithm. eg
String UId = "k5abv4oduaidu8knel4088iq8c#google.com";
String Header = "040000008200E00074C5B7101A82E008";
String Padding = "0000000000000000000000000000000000000000";
String Prefix = "7643616C2D55696401000000";
String DataString = Prefix + BitConverter.ToString(ASCIIEncoding.ASCII.GetBytes(UId)).Replace("-", "") + "00";
String BigEndianlength = (DataString.Length / 2).ToString("X8");
String LittleEndianlength = BigEndianlength.Substring(6, 2) + BigEndianlength.Substring(4, 2) + BigEndianlength.Substring(2, 2) + BigEndianlength.Substring(0, 2);
String GlobalUidHex = Header + Padding + LittleEndianlength + DataString;
If you then conver the HexString to Base64 String that should work.
Cheers
glen
Related
I have a moment.Duration object which I need to convert to string format HH:mm:ss (without any timezone conversion). I know we can do like
foobar.hours + ":" + foobar.minutes + ":" + foobar.seconds
But honestly I was hoping to have a better solution that just string manipulations.
var now = moment()
var then = moment().subtract(3, 'hours').subtract(20, 'minutes')
const duration = now.subtract(then)
duration.format("HH:mm:ss")
>> 03:20:00
moment().format('HH:mm:ss');
if u have already moment object use like this
object.format('HH:mm:ss');
How do I get the full message and not just the metadata using gmail api?
I have a service account and I am able to retrieve a message but only in the metadata, raw and minimal formats. How do I retrieve the full message in the full format? The following code works fine
var request = service.Users.Messages.Get(userId, messageId);
request.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Metadata;
Message message = request.Execute();
However, when I omit the format (hence I use the default format which is FULL) or I change the format to UsersResource.MessagesResource.GetRequest.FormatEnum.Full
I get the error: Metadata scope doesn't allow format FULL
I have included the following scopes:
https://www.googleapis.com/auth/gmail.readonly,
https://www.googleapis.com/auth/gmail.metadata,
https://www.googleapis.com/auth/gmail.modify,
https://mail.google.com/
How do I get the full message?
I had to remove the scope for the metadata to be able to get the full message format.
The user from the SO post have the same error.
Try this out first.
Go to https://security.google.com/settings/security/permissions
Choose the app you are working with.
Click Remove > OK
Next time, just request exactly which permissions you need.
Another thing, try to use gmailMessage.payload.parts[0].body.dataand to decode it into readable text, do the following from the SO post:
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
System.out.println(StringUtils.newStringUtf8(Base64.decodeBase64(gmailMessage.payload.parts[0].body.data)));
You can also check this for further reference.
try something like this
public String getMessage(string user_id, string message_id)
{
Message temp =service.Users.Messages.Get(user_id,message_id).Execute();
var parts = temp.Payload.Parts;
string s = "";
foreach (var part in parts) {
byte[] data = FromBase64ForUrlString(part.Body.Data);
s += Encoding.UTF8.GetString(data);
}
return s
}
public static byte[] FromBase64ForUrlString(string base64ForUrlInput)
{
int padChars = (base64ForUrlInput.Length % 4) == 0 ? 0 : (4 - (base64ForUrlInput.Length % 4));
StringBuilder result = new StringBuilder(base64ForUrlInput, base64ForUrlInput.Length + padChars);
result.Append(String.Empty.PadRight(padChars, '='));
result.Replace('-', '+');
result.Replace('_', '/');
return Convert.FromBase64String(result.ToString());
}
Im trying to add viewmodel objects into cookie using angularjs2. I have tried a lot, but didn't worked yet. I
private setCookie(name: string, value: any, expireDays: number, path: string = "") {
let d: Date = new Date();
d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
let expires: string = "expires=" + d.toUTCString();
document.cookie = name +`enter code here` "=" + value + "; " + expires + (path.length > 0 ? "; path=" + path : "");
}
I have tried like this,
this.setCookie("CookieConstant", ViewModel, 1);
When I'm checking cookie value in the browser I can see only [Object Object]. Can anyone help me. I'm new to angular 2
I think its not possible in angular 2, you better to set single value in the cookie, based on that value you can generate the results. Cookies is for setting small values, so its better to avoid setting viewmodel objects into cookies. Try to set single value.
I've tried this on different links and it would work but specifically on this link it won't work:
ticker = 'SBUX'
url = urlfetch.fetch('http://stockcharts.com/h-sc/ui?s=' + ticker +
'&p=D&yr=1&mn=0&dy=0&id=p97813671848')
# Parses the HTML
tree = etree.HTML(url.content)
# Converts the DOM into a string
result = etree.tostring(tree, pretty_print=True, method="html")
self.response.out.write(result)
I don't know why it cannot fetch the stockcharts link?
Could it be that stockcharts blocks google?
Weird. Seems to work with urllib though ...
ticker = 'SBUX'
uri = 'http://stockcharts.com/h-sc/ui?s=' + ticker + '&p=D&yr=1&mn=0&dy=0&id=p97813671848'
response = urllib2.urlopen(uri)
html = response.read()
I'm working on a project where i need to post the data i acquire to a Google form and obtain the data from the spreadsheet. I cannot use google apps script and need a method using the direct POST method as i will be doing this function from a GSM module. All the solutions posted previously take into consideration the old structure of the Google form which provides a form key.Like the solution described in this one:
http://www.open-electronics.org/how-send-data-from-arduino-to-google-docs-spreadsheet/
The link to my current form is this.
https://docs.google.com/forms/d/14MkYG3fPNezzUC_nXUsWHlZ5JhplvjyWTAeob7f_W7g/viewform
Any help would be appreciated.
Is it a requirement that a google form be in the middle of this? If it is enough to be able to post your data to a spreadsheet, here's a Google-Apps-Script for one side of the problem: a simple web service that will accept form data as a query string, and write that to your spreadsheet.
This examples assumes a very simple spreadsheet, with three columns, "Timestamp", "col1" and "col2". Edit the code to suit your situation.
You can see the spreadsheet here, and even make a test post.
/**
* doGet() function to add data to a spreadsheet.
*
* Spreadsheet data is provided as a querystring, e.g. ?col1=1&col2='pizza'
*
* From: http://stackoverflow.com/a/18725479/1677912
*
* #param {event} e Event passed to doGet, with querystring
* #returns {String/html} Html to be served
*
* Test URLs (adjust ID as needed):
* https://script.google.com/macros/s/--DEV-SCRIPT-ID--/dev?col1=1&col2='pizza'
* https://script.google.com/macros/s/--PUB-SCRIPT-ID--/exec?col1=1&col2='pizza'
*/
function doGet(e) {
Logger.log( JSON.stringify(e) ); // view parameters
var result = 'Ok'; // assume success
if (e.parameter == undefined) {
result = 'No Parameters';
}
else {
var id = '--SHEET-ID---'; // Spreadsheet id for responses
var sheet = SpreadsheetApp.openById(id).getActiveSheet();
var newRow = sheet.getLastRow() + 1;
var rowData = [];
rowData[0] = new Date(); // Timestamp
for (var param in e.parameter) {
Logger.log('In for loop, param='+param);
var value = stripQuotes(e.parameter[param]);
//Logger.log(param + ':' + e.parameter[param]);
switch (param) {
case 'col1':
rowData[1] = value;
break;
case 'col2':
rowData[2] = value;
break;
default:
result = "unsupported parameter";
}
}
Logger.log(JSON.stringify(rowData));
// Write new row to spreadsheet
var newRange = sheet.getRange(newRow, 1, 1, rowData.length);
newRange.setValues([rowData]);
}
// Return result of operation
return ContentService.createTextOutput(result);
}
/**
* Remove leading and trailing single or double quotes
*/
function stripQuotes( value ) {
return value.replace(/^["']|['"]$/g, "");
}
You can do the sending with the new forms, there is a menu option for it. (Responses->Get prefill url) It gives the url for posting data to a form.
You also asked: "obtain the data from the spreadsheet":There are two ways, google apps script and gdata style "google-spreadsheet-api". But I suggest you use a mix of google apps script and "arduino" style code, as it has better docs and features than gdata style api.
p.s. I created some formulas for creating an "arduino" user interface a while back.