Hi i created a plugin portlet. In the JSP i am accessing all countries list by using JSON API. It is working fine for Logged in users. But for the Guest users i am unable to access the web service. I am working on Liferay 6.0.6. The following is my code.
Liferay.Service.Portal.Country.getCountries(
{},
function(result) {
for(var count=0;count< result.length;count++){
alert(result[count].name);
var option = document.createElement("option");
}
}
);
Assuming that you are using Liferay 6.1, you can achieve it by adding a property to portal-ext.properties file
json.service.public.methods=getCountries
If you need to check the whole flow checkout
JSONServiceAction
I think you need to pass the serviceContext with permissions to the Service.
Can you try by setting the communityPermissions and guestPermissions as VIEW ?
Liferay.Service.Portal.Country.getCountries(
{
serviceContext: jQuery.toJSON(
{
communityPermissions: communityPermission,
guestPermissions: guestPermission,
scopeGroupId: themeDisplay.getScopeGroupId()
}
)
},
function(result) {
for(var count=0;count< result.length;count++){
alert(result[count].name);
var option = document.createElement("option");
}
}
);
I found a work around for the above problem. I am unable to access JSON API because Liferay is using A.io.request for AJAX Calls which is available for Logged in Users only. So I have prepared the following code.
jQuery.ajax({
type: "POST",
url: '<%=themeDisplay.getURLPortal() %>'+'/tunnel-web/json?serviceClassName=com.liferay.portal.service.CountryServiceUtil&serviceMethodName=getCountries',
dataType: 'json',
success: function(countriesList) {
alert(countriesList);
alert(countriesList[0].countryId);
}
}
});
Related
I am working on a POSTMAN collection. Say, I have two separate postman environments with each having URL variables, lets domain1 & domain2. In my initial script in pre-request tab I want to get a list of all the environments available so I can switch them when I need to. How do I get the list of environments?
Thanks,
Thanks Christian Bauman. I was able to accomplish by doing following
In postman Pre-request Script tab. The response will contain environment array with object having id, name, owner, uid properties. you can then call by id to get further details of an environment.
let options = {
method: 'GET',
url: 'https://api.getpostman.com/environments',
header: {
'x-api-key': 'PMAK-your own key goes here'
},
json: true
};
let envs = [];
pm.sendRequest(options, function(err, response) {
if (!err) {
let data = response.json();
_.forEach(data.environments, function(item) {
envs.push(item);
});
console.log(envs);
} else {
console.log(err);
}
});
It is not possible to select environment from scripts. the closest one can get, is to receive the name of the currently active environment: pm.environment.name
I'm using the Glip API to post messages. I can post images from the Glip UI but I don't see an option to post images. Does anyone know how to do this?
Glip API: https://developer.ringcentral.com/api-docs/latest/index.html#!#RefGlipCreatePost
Glip recently launched the file upload API which can be used to attach images. You could also try it out using our API Explorer.
In case someone comes across this looking for a working example, here's what I did (using Node and the RingCentral SDK):
var RC = require('ringcentral');
var fs = require('fs');
var FormData = require('form-data');
// {login to Glip and generate the platform object (https://github.com/ringcentral/ringcentral-js)}
var formData = new FormData();
formData.append('attachment', fs.createReadStream('image.png'));
platform
.send({
method: 'POST',
url: '/glip/files',
body: formData,
query: {
groupId: '1234', // whatever group you want to post to
}
})
.then(function(){
console.log('file uploaded');
})
.catch(function(e){
console.log(e.message);
});
Hello i have deployed my project in ionic view where i need to make a http call to remote server.I have implemented proxies like this
{
"name": "MobileUI",
"app_id": "608c237d",
"type": "ionic-angular",
"proxies": [
{
"path": "/Auth",
"proxyUrl": "https://example.com/Auth/Authenticate",
"rejectUnauthorized": false
}
]
}
And I make a login call to the from the provider like this
AuthenticateUser(username: string, password: string) {
var userNamePwd: any = {};
userNamePwd.username = username;
userNamePwd.password = password;
let body = JSON.stringify(userNamePwd);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post('/Auth', body, options)
.map((res) => {
let data = this.extractData(res);
this.storage.set('id_token', data[0].Token);
this.sharedAuth.SetEntityData(data);
return data;
})
.catch(this.handleError);
}
The Login works perfectly when testing in web browser but when i upload the app in my ionic view i am getting this error response with status 0 for url null
I implemented the proxies in the way mentioned in http://blog.ionic.io/handling-cors-issues-in-ionic/ .
Am I missing something ?
the issue is that when you run the app in ionic view app, there is no local proxy to forward requests to your backend. So you get into cors issues because the local webview enforce strict cors in the ionic view app.
I hope the ionic team comes up with a fix. As for now, to my best knowledge, you should modify your backend to allow all origins, or use a web server as a proxy to forward your request to your api servers.
I've been working all week to get authentication working. I have gotten it working with
Ember-CLI
Ember-Simple-Auth
Torii
google-oauth2 provider
However I have proven unsuccessful in getting the users information from google. I have tried creating a torii-adapter as stated in their documentation but it doesn't appear to be called
// app/torii-adapters/application.js
export default Ember.Object.extend({
open: function(authorization){
console.log('authorization from adapter', authorization);
}
});
I've exhausted my google-foo and am asking for your assistance. This is a great library combination for authorization however the documentation is lacking for this case, and when figured out I will be sure to contribute back.
Thank you
The problem I was encountering is Torii's default google-oauth2 provider doesn't access this info for you, also it uses the code workflow instead of the token workflow which is needed for the google+ API
To fix this I wrote a custom provider that uses a jquery GET request to the G+ API, I then return the userName and userEmail to access it in the session under content.
I wrote a full tutorial detailing authorizing an ember app using google start to finish here
//app/torii-providers/google-token.js
import {configurable} from 'torii/configuration';
import Oauth2Bearer from 'torii/providers/oauth2-bearer';
var GoogleToken = Oauth2Bearer.extend({
name: 'google-token',
baseUrl: 'https://accounts.google.com/o/oauth2/auth',
// additional params that this provider requires
requiredUrlParams: ['state'],
optionalUrlParams: ['scope', 'request_visible_actions', 'access_type'],
requestVisibleActions: configurable('requestVisibleActions', ''),
accessType: configurable('accessType', ''),
responseParams: ['token'],
scope: configurable('scope', 'email'),
state: configurable('state', 'STATE'),
redirectUri: configurable('redirectUri',
'http://localhost:8000/oauth2callback'),
open: function(){
var name = this.get('name'),
url = this.buildUrl(),
redirectUri = this.get('redirectUri'),
responseParams = this.get('responseParams');
var client_id = this.get('client_id');
return this.get('popup').open(url, responseParams).then(function(authData){
var missingResponseParams = [];
responseParams.forEach(function(param){
if (authData[param] === undefined) {
missingResponseParams.push(param);
}
});
if (missingResponseParams.length){
throw "The response from the provider is missing " +
"these required response params: " + responseParams.join(', ');
}
return $.get("https://www.googleapis.com/plus/v1/people/me", {access_token: authData.token}).then(function(user){
return {
userName: user.displayName,
userEmail: user.emails[0].value,
provider: name,
redirectUri: redirectUri
};
});
});
}
});
export default GoogleToken;
I have the facebook page and all photos and albums are public.
I've used previously this query for get all albums:
https://graph.facebook.com/67695062976/albums
Now this query writes this error:
An access token is required to request this resource.
My javascript function for get all albums:
getAlbums: function()
{
$.get('http://graph.facebook.com/67695062976/albums?callback=?', {
}, function (res) {
$('#AlbumsContent').html("");
$.each(res.data, function (key, value) {
var image = res.data[key];
$('#AlbumsContent').append('<div class="PhotosAlbums"><a id="buttonPhotosAlbums'+image.id+'" href="album-'+image.id+'"></a><div class="PhotosAlbumsName">'+image.name+'</div></div>');
});
}, "json");
},
How can i fix this problem in javascript side?
You need an Access Token for almost everything now, for public stuff of pages you can just use an App Access Token, which is the App Id and The App Secret, combined with a pipe:
App-ID|App-Secret
There you go:
https://graph.facebook.com/67695062976/albums?access_token=App-ID|App-Secret
If you did not create an App yet, this is where you do it: https://developers.facebook.com/apps