create a private group via the yammer API - yammer

Is there a way to create a private group using the "yammer API"?

You can use below code
yam.platform.request({
// yam.request({
url: "groups.json?name=Group_Name&private=true",
method: "POST",
data: {},
success: function (group) {
console.dir(group);
getMyGroups();
},
error: function (group) {
console.error("There was an error with the request.");
}
});

No. You can only join/leave an existing group for the current user. See https://developer.yammer.com/restapi/#rest-groups

You can create a new group in Yammer using REST API.
Endpoint:
POST https://www.yammer.com/api/v1/groups.json
Parameters:
name - [string], group name
description - [string], group description
private - [true/false], indicates whether group is private
So you can send this request to Yammer API to create a new private group.
POST https://www.yammer.com/api/v1/groups.json?name=new_group_name&private=true

Actually, it looks like you can via an undocumented api.
See this code:
https://github.com/OfficeDev/PnP/tree/master/Scenarios/Provisioning.Yammer
See this specific line:
// Get Yammer Group - Creates if does not exist
YammerGroup group =
YammerUtility.CreateYammerGroup(yammerGroupName, true, ConfigurationManager.AppSettings["YammerAccessToken"]);

Related

Gmail API for managing multiple signatures

Google recently released an update to Gmail to bring support for multiple signatures. Ref: https://support.google.com/mail/answer/8395.
I do not see anything in the API documentation at https://developers.google.com/gmail/api/v1/reference that talks about how to manage those multiple signatures. How can I:
create a new signature
update a specific existing signature
associate a signature to an email address - both the "for new emails use" and "on reply/forward use"
Is there any documentation on this?
It is a bit hidden, the signature(s) need to be created with Users.settings.sendAs: create or update
As specified for the resource, signature is one of the parameters that can be modified and you do not need to create a new alias, but can also apply this method to your primaary email:
Settings associated with a send-as alias, which can be either the
primary login address associated with the account or a custom "from"
address.
Important: Access restricted to service accounts that have been delegated
Sample with Apps Script:
function createAlias() {
var alias = 'your primary email';
var signature = 'Your signature';
var service = getOAuthService();
service.reset();
if (service.hasAccess()) {
var url = 'https://www.googleapis.com/gmail/v1/users/me/settings/sendAs'
var headers ={
"Authorization": 'Bearer ' + service.getAccessToken(),
"Accept":"application/json",
"Content-Type":"application/json",
};
var resource ={
sendAsEmail: alias,
signature: signature,
};
var options = {
'headers': headers,
'method': 'POST',
'payload':JSON.stringify(resource),
'muteHttpExceptions': true
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
}
Necessary scope:
https://www.googleapis.com/auth/gmail.settings.sharing

Google Cloud Platform: Unable to upload a new file version in Storage via API

I wrote a script that uploads a file to a bucket in Google Cloud Storage:
Ref: https://cloud.google.com/storage/docs/json_api/v1/objects/insert
function submitForm(bucket, accessToken) {
console.log("Fetching the file...");
var input = document.getElementsByTagName('input')[0];
var name = input.files[0].name;
var uploadUrl = 'https://www.googleapis.com/upload/storage/v1/b/'+
bucket + '/o?uploadType=media&access_token=' + accessToken + '&name=' + name;
event.preventDefault();
fetch(uploadUrl, {
method: 'POST',
body: input.files[0]
}).then(function(res) {
console.log(res);
location.reload();
})
.catch(function(err) {
console.error('Got error:', err);
});
}
It works perfectly fine when uploading a new file.
However, I get a 403 status code in the API response body while trying to replace an existing file with a new version.
Please note that:
The OAuth 2.0 scope for Google Cloud Storage is: https://www.googleapis.com/auth/devstorage.read_write
I did enable the versioning for the destination bucket
Could someone help me in pointing out what I did wrong?
Update I:
As suggested, I am trying to invoke the rewrite function as follows:
const input = document.getElementsByName('uploadFile')[0];
const name = input.files[0].name;
const overwriteObjectUrl = 'https://www.googleapis.com/storage/v1/' +
'b/' + bucket +
'/o/' + name +
'/rewriteTo/b/' + bucket +
'/o/' + name;
fetch(overwriteObjectUrl, {
method: 'POST',
body: input.files[0]
})
However, I am getting a 400 (bad request error).
{"error":{"errors":[{"domain":"global","reason":"parseError","message":"Parse Error"}],"code":400,"message":"Parse Error"}}
Could you explain me what I am doing wrong?
Update II:
By changing body: input.files[0] with body: input.files[0].data I made it working... Theoretically!
I get a positive response body:
{
"kind":"storage#rewriteResponse",
"totalBytesRewritten":"43",
"objectSize":"43",
"done":true,
"resource":{
"kind":"storage#object",
"id":"mybuck/README.txt/1520085847067373",
"selfLink":"https://www.googleapis.com/storage/v1/b/mybuck/o/README.txt",
"name":"README.txt",
"bucket":"mybuck",
"generation":"1520085847067373",
"metageneration":"1",
"contentType":"text/plain",
"timeCreated":"2018-03-03T14:04:07.066Z",
"updated":"2018-03-03T14:04:07.066Z",
"storageClass":"MULTI_REGIONAL",
"timeStorageClassUpdated":"2018-03-03T14:04:07.066Z",
"size":"43",
"md5Hash":"UCQnjcpiPBEzdl/iWO2e1w==",
"mediaLink":"https://www.googleapis.com/download/storage/v1/b/mybuck/o/README.txt?generation=1520085847067373&alt=media",
"crc32c":"y4PZOw==",
"etag":"CO2VxYep0NkCEAE="
}
}
Whit as well a new generation number (versioning enabled).
However, the file content has been not updated: I did append new strings but they did not show off within the file. Do you have any idea?
Thanks a lot in advance.
Based on the information available it's difficult to diagnose this issue with certainty- however I would check the roles assigned to the user or service account you are using for this operation.
As you have been able to upload a file, but not overwrite a file, this sounds like you may have assigned the user or service account that is attempting to perform this task the 'Storage Object Creator' role.
Users/service accounts with the Storage Object Creator role can create new objects in buckets but not overwrite existing ones (you can see this mentioned here).
If this is the case, you could try assigning the user/service account the role of 'Storage Object Admin' which allows users full control over bucket objects.
"insert" is only to be used to create new objects per the Methods section of the API's documentation, so you'll need to use "rewrite" to rewrite an existing object.

Possible Parse bug in matchesKeyInQuery

If a post in my Parse database is liked, I want to send a push to the author via cloud code.
To be able to send pushes to specific users, all installations store the objectId of the current user. To find the author of the liked post, I use the query
var userWhosePostWasLikedQuery = new Parse.Query(Parse.Installation);
userWhosePostWasLikedQuery.equalTo(kClassInstallationKeyCurrentUserId, userWhosePostWasLiked.id);
This works fine: A single push is sent to the author.
Now I want to send this push only if the author has such pushes enabled. Thus each user stores a push settings array with enable flags for different pushes.
I use now another query for all users who have such pushes enabled:
const User = Parse.Object.extend(kClassUser);
var pushEnabledUserQuery = new Parse.Query(User);
pushEnabledUserQuery.equalTo(kClassUserKeyPushSettings, kPushNotificationTypePostLiked);
This query correctly returns all users who have such pushes enabled.
Eventually, I want to constrain the query for installations with the author as current user, by this query for users who have pushes enabled. This is done in the following way:
var userWhosePostWasLikedQuery = new Parse.Query(Parse.Installation);
userWhosePostWasLikedQuery.equalTo(kClassInstallationKeyCurrentUserId, userWhosePostWasLiked.id);
userWhosePostWasLikedQuery.matchesKeyInQuery(kClassInstallationKeyCurrentUserId, kPFObjectId, pushEnabledUserQuery);
Since the old query without the 3rd line returns 1 user, the new query with the additional constraint (matchesKeyInQuery) should return the same user, since the author has pushes enabled.
But it returns 2 users, the author and another user who liked the post.
To my understanding, this looks like a Parse bug, since all constraints to a query are ANDed.
Any ideas, maybe for a workaround?
your var "kPFObjectId" should be change to "user".
the default parse Installation come with the pointer named "user" and not "kPFObjectId".
I can tell you that Im using the same method ("matchesKeyInQuery") and it is working well:
Parse.Cloud.define("sendPushForChat", function(request, response) {
var userId = request.params.userId;
var groupId = request.params.groupId;
var query = new Parse.Query('RecentActivity');
query.equalTo('groupId',groupId);
query.include('user');
query.notEqualTo('user', {__type: "Pointer", className: "_User", objectId: userId});
var queryInstallation = new Parse.Query(Parse.Installation);
queryInstallation.matchesKeyInQuery('user', 'user', query);
var message = request.params.messageContent;
Parse.Push.send({
where: queryInstallation,
data: {
alert: message,
badge: "Increment",
title: "מה נשמע?"
}
}, {
success: function() {
console.log("Push for chat was successful");
response.success('Push for chat was successful');
},
error: function(error) {
console.error(error);
response.error('error');
},
useMasterKey:true,
});
})

extjs store with ajax serving multi read requests

Unanswered: store ajax serving multi read requests (best practice question)
Hi, im trying to understand the proper design concept of Store proxies using the Ajax api config and have a question on how this should be done.
suppose i have a store which has a server proxy using the Ext.data.proxy.Ajax class and i have an api with the following:
proxy: {
type: 'ajax',
api: {
read: 'some/something/list.json',
create: 'some/something/insert.json',
update: 'some/something/update.json',
destroy: 'some/something/destroy.json'
}
}
now suppose my read is triggered by a search button and when i have a blank text box and click search it makes a request through the read api to retrieve the list.json. but i want to have another read as part of the same store / api to read individual records say something like this:
read: 'some/something/<field_value>.json'
my proxy read is already assigned to the list.json but i want to allow the same store proxy to be able to read from individual record searches also. granted that i cant have two read statements in my proxy. how would I go about writing this?
help me understand? maybe my server controller has to be able to determine by keyword #PathVariable if path is list i.e .json then call the list db query otherwise if .json then run the individual search query through the db.?? and if so what would be the read: url?
whats the best way to design and build this?
Thanks in advance
If you want to read single record instead of defining proxy in store you should do it in Model and then call load on model itself something like below.
Ext.define('app.model.User', {
{
fields: [
{ name: 'LoginUserId', type: 'string' },
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' }],
proxy:
{
type: 'rest',
url: '/User',
reader:
{
type: 'json',
root: ''
}
}
});
var user = Ext.ModelMgr.getModel('app.model.User');
user.load(123, {
success: function(userObj) {
}
});

Mojo SDK retrieve all contacts

I'm playing with the Mojo SDK and I want to get all contacts.
this.controller.serviceRequest('palm://com.palm.contacts/crud', {
method: 'listContacts',
parameters: {
limit: 100
},
onSuccess: this.handleListResponse.bind(this),
onFailure: function(errResp){
Mojo.Log.info(errResp.errorText)
}.bind(this),
onerror: function(errResp){
Mojo.Log.info(errResp.errorText)
}.bind(this)
});
This is what I have right now, but I don't get anything back. And Mojo.Log.info doesn't seem to work. Any suggestions?
Thanks
I'm also fairly new at PRE development but here is what I think the issue is.
The error that comes back is "Account Not Found". You need to add accountId: as a parameter to the service request.
That account id, according to the documentation, is a Synergy account and needs to be created for your application. Click here for reference about the accountId and createAccount methods

Resources