Linkedin REST API Auth and JSAPI call, Rails/Omniauth - ruby-on-rails

I lost my temper few days ago because of this simple problem. Can you help me on this?
I'm suppose, since it's written in the Linkedin JS API documentation here, to be able to logion with REST and launch calls with JSAPI :
https://developer.linkedin.com/documents/inauth-inevent-and-inui
Authorization Tokens
While the easiest method of authenticating a user for the JSAPI is to
use one of the login buttons, some sites have implemented the OAuth
1.0a flow used by the REST API. Whichever type of authentication you use for the user, the JSAPI will recognize that the member has already
logged in, as long as the key and hostname are the same. This happens
automatically, requiring no additional code by the developer.
But this is NOT working, I have this weird console error :
Cannot call method 'Profile' of undefined
when I call this right after REST auth:
IN.API.Profile("me").fields(["id", "..."]).result(linkedin_connect_save);
Any ideas?

That console error doesn't have anything to do with authentication - I'm guessing you're loading another javascript framework which is interfering with the LinkedIn framework and the IN object isn't getting properly loaded.
The following page works with a key that I've previously authenticated using REST in the same browser here: http://developer.linkedinlabs.com/tutorials/testing.html
<html>
<head>
<title>Connections App Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body class="yui3-skin-sam yui-skin-sam">
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: MY_API_KEY
onLoad: loadData
authorize: true
</script>
<script type="text/javascript">
function loadData() {
IN.API.PeopleSearch()
.fields("firstName", "lastName", "distance", "publicProfileUrl","pictureUrl")
.params({"keywords": "princess", "count": 10, "sort": "distance"})
.result(function(result) {
alert(JSON.stringify(result));
});
}
</script>
</body>
</html>

your code might call before js load..
include js before ur code..

Related

How to get currently playing/recently played songs using Spotify web API

I am trying to integrate web API to get currently playing/recently played songs. But, I could not generate the token with the scopes (user-read-currently-playing, user-read-playback-state).
I followed this link as refrence of Spotify. https://developer.spotify.com/web-api/authorization-guide/
1 https://accounts.spotify.com/authorize/?client_id=[CLIENT_ID]&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=user-read-currently-playing%20user-read-playback-state&state=34fFs29kd09
I am getting bellow HTML response.
<html ng-app="accounts" ng-csp="">
<head>
<meta charset="utf-8">
<title ng-bind="(title && (title | localize) + ' - ') + 'Spotify'">Spotify</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<base href="/">
<link href="https://d2d1dxiu3v1f2i.clou..." media="screen" rel="stylesheet">
<script async="" defer="" src="https://d2d1dxiu3v1f2i.clou..." sp-bootstrap=""></script>
<meta ng-non-bindable="" sp-bootstrap-data="">
</head>
<body ng-view=""></body>
</html>
Please help.
Thank you
It looks like you've slightly misunderstood the auth procedure - in the authorization code flow the first step is to present that page to your user. You can do this in an iframe, a popup, in the original window - however you like. Once the user has granted or declined permission on that page, they will be redirected back to your app using the redirect URI.
To complete the authorization code flow, you have to exchange the code you get in the redirect for an access token and a refresh token. To perform this exchange, you'll need the client server - which mustn't be stored in your web frontend. You'd need a backend that'll do the exchange and forward the user to your frontend with the access token. If you don't have a backend, you can use the implicit grant flow.
Hope that helps!
Hugh

Accessing Twitter Sample Streaming Endpoint?

I'm trying to access the following GET https://stream.twitter.com/1.1/statuses/sample.json end-point in these docs.
From POSTMAN, I set an Authorization header with a value of Basic X where X is equal to the base64 encoding of $ConsumerKey:$ConsumerSecret.
When issuing the GET call from POSTMAN, I see the following prompt:
Confused as to why my OAuth credentials aren't accepted, I entered my Twitter user and password.
But, the server replies with:
<html>\n
<head>\n
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n
<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/statuses/sample.json'. Reason:
<pre> Unauthorized</pre>
</body>
</html>
In addition, I typed in my Consumer Key and Secret for the user and password prompt, but that failed too.
So, how can I hit this endpoint from POSTMAN? I'm not entirely sure if it's a stream. If it is, would I still be able to hit it via POSTMAN?

How do I get Custom Variables in Google Analytics to work using Async method?

So, I'm researching how to use Google Analytics by applying it to a test site I've built using VB.NET and MVC5. I'm using the Async method since that seems to be what the Google Developers site is recommending.
In my _Layout.vbhtml (which Visual Studio automatically generated for me) I have the following code between my <head> and </head> tags:
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#ViewBag.Title - My ASP.NET Application</title>
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
<script>
window.ga = window.ga || function () { (ga.q = ga.q || []).push(arguments) }; ga.l = +new Date;
ga('create', 'UA-75489237-2', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<script>
_gaq.push(['_setCustomVar',
5, // This custom var is set to slot #5. Required parameter.
'CusVarTest', // The top-level name for your online content categories. Required parameter.
'Successful', // Sets the value of "Section" to "Life & Style" for this particular aricle. Required parameter.
3 // Sets the scope to page-level. Optional parameter.
]);
</script>
</head>
Now, theoretically, this should be working, but when I go to the Google Analytics site, and go to "Reporting --> Audience --> Custom --> Custom Variables" I am seeing no sign of my variable.
Any thoughts?
A few things:
you are mixing older classic GA syntax (_gaq.push(['_setCustomVar', ...) with the new UA syntax (ga('create', 'UA-75489237-2', 'auto');). That's not going to work. I advise you to make sure you are using only UA code.
Custom Variables have been phased out of UA, so you will need to use the UA analogs called "Custom dimensions" (cf. https://support.google.com/analytics/answer/2709828?hl=en). This includes no longer using the Custom Variables in the reports.
data takes up to 24 hours to process, so you won't see things right away in your reports unless you wait a day, or you could try using GA Debugger or console tools to verify that your data is properly set and sent.

Integrating Activiti Explorer with Ruby on Rails project

I have tried several different methods to accomplish this and none have been successful. Ive tried jruby, the rest api for activiti (this does not update the UI and is thus not suited for my purposes), and the mechanize gem. The mechanize gem did not work because of the VAADIN UI that activiti explorer ships with or so I think. I currently have activiti hosted in an iframe in my rails app, and am trying to find a way to communicate between the two. I used the gem like this:
agent= Mechanize.new
agent.redirection_limit= 10
//page is used three times to illustrate different routes taken.
page= agent.get('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/)
page= agent.post('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/ui/APP/2/login',{'username'=>'kermit', 'password'=>'kermit'} )
page=agent.put('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/ui/1/loginHandler',{'username'=>'kermit', 'password'=>'kermit'})
here is a sample response from activiti explorer when mechanize is used:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">html, body {height:100%;margin:0;}</style><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/favicon.ico" /><link rel="icon" type="image/vnd.microsoft.icon" href="/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/favicon.ico" /><title>Activiti Explorer</title>
</head>
<body scroll="auto" class="v-generated-body">
<script type="text/javascript">
//<![CDATA[
if(!vaadin || !vaadin.vaadinConfigurations) {
if(!vaadin) { var vaadin = {}}
vaadin.vaadinConfigurations = {};
if (!vaadin.themesLoaded) { vaadin.themesLoaded = {}; }
}
vaadin.vaadinConfigurations["activitiwebappexplorer25180ui-1091631569"] = {appUri:'/activiti-webapp-explorer2-5.18.0/ui', standalone: true, themeUri:"/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti", versionInfo : {vaadinVersion:"6.8.8",applicationVersion:"NONVERSIONED"},"comErrMsg": {"caption":"Communication problem","message" : "Take note of any unsaved data, and <u>click here<\/u> to continue.","url" : null},"authErrMsg": {"caption":"Authentication problem","message" : "Take note of any unsaved data, and <u>click here<\/u> to continue.","url" : null}};
//]]>
</script>
<iframe tabIndex='-1' id='__gwt_historyFrame' style='position:absolute;width:0;height:0;border:0;overflow:hidden;' src='javascript:false'></iframe>
<script language='javascript' src='/activiti-webapp-explorer2-5.18.0/VAADIN/widgetsets/org.activiti.explorer.CustomWidgetset/org.activiti.explorer.CustomWidgetset.nocache.js?1444407987049'></script>
<script type="text/javascript">
//<![CDATA[
if(!vaadin.themesLoaded['activiti']) {
var stylesheet = document.createElement('link');
stylesheet.setAttribute('rel', 'stylesheet');
stylesheet.setAttribute('type', 'text/css');
stylesheet.setAttribute('href', '/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/styles.css');
document.getElementsByTagName('head')[0].appendChild(stylesheet);
vaadin.themesLoaded['activiti'] = true;
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
setTimeout('if (typeof org_activiti_explorer_CustomWidgetset == "undefined") {alert("Failed to load the widgetset: /activiti-webapp-explorer2-5.18.0/VAADIN/widgetsets/org.activiti.explorer.CustomWidgetset/org.activiti.explorer.CustomWidgetset.nocache.js?1444407987049")};',15000);
//]]>
</script>
<div id="activitiwebappexplorer25180ui-1091631569" class="v-app v-theme-activiti v-app-ExplorerApp" ><div class="v-app-loading"></div></div>
<noscript>You have to enable javascript in your browser to use an application built with Vaadin.</noscript></body>
</html>
I have tried all of the possible url's I could see on the UI, but none of them work. I have tried all of post, get, and put with each of these three urls .I found these URL's by looking at the loaded page, and noticing that they are nested iframes. Any help in seeing the feasiblity of the mechanize gem would be great, as feel as if this would be an easy fix to my problem. As a side note, I have changed the tomcat properties to allow for CORS requests. Also, http requests from rails to activiti explorer do not work either, so that form of communication is also out.
Also if you are familiar with activiti- I have edited the authenticate method in default login handler to try and parse http requests to get the username and password to login automatically. This however returns the same html code as printed above. Any help would be greatly appreciated. Here is a sample of the http requests I make from rails:
auth = {:userid=> "kermit", :password => "kermit"}
puts HTTParty.get("http://activiti.testing.com:8080/activiti-webapp-explorer2-5.18.0/", :content_type => "application/json",
:basic_auth => auth)
I think integrating Activiti Explorer in iframe is not a good idea. Since your username and password are exposed! And the requirements of the frontend are various.
I like Activiti Explorer at first, Modeler is really awesone! But I use Rails and find it hard to customize and integrate Activiti Explorer later. I tried integrate with Activiti REST, while I prefer Activiti Java API for the following reasons:
Activiti REST is a subset of Activiti Java API. eg: SetProcessDefinitionVersionCmd is not availiable in Activiti REST.
Performance concerns. I develop a task web page, but it needs over 10 http requests.
I like Acitivi Modeler and Diagram Viewer. I need Activiti Explorer running and make them work together.
So I develop a gem named jruby_activiti, integrating Activiti Engine, Modeler and Diagram Viewer. All these are availiable in JRuby on Rails! Hope my experiences could help you.

Google Mobile Ads SDK App Events with Click Tracking

We are displaying some ads in our iOS & Android applications using the Google Mobile Ads SDK. We need some parameters to make a web service call when the user clicks on the Ad and we get them using the GADAppEventDelegate, and after the web service call we present a custom screen. (so we don't want to redirect the user to a Web Page). The problem is that the Clicks are not tracked and we believe that Ad Creative might not be configured right.
<html><body leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<html>
<head>
<script src="http://media.admob.com/api/v1/google_mobile_app_ads.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function fireEvent() {
admob.events.dispatchAppEvent("query_string", "ad_origin_key=USPS2013_iPhone_Upgraded_320x50&k_key=&acid_key=719768856&ad_image_url_key=http://USPS2013_iphone_320x50");
}
</script>
</head>
<body>
<img src="http://pagead2.googlesyndication.com/pagead/imgad?id=CICAgIDQ59KwChABGAEyCKGNWPM-wPBl" width="320" height="50" border="0" onclick="fireEvent()"/>
</body>
</html></body></html>
I believe that in order not to be redirected to a Web Page we should make an AJAX request in fireEvent() function, something like $.get("%%CLICK_URL_UNESC%%www.example.com/ads/landingpage"); but the browser doesn't allow AJAX request to a server different of the original request server.
So how could we solve this issue, track the clicks and not navigate to a new web page?
Thanks
Hello i think this answer is a bit late but the code you quoted actually works!!
Inside your head tag of HTML of the creative
<script src="http://media.admob.com/api/v1/google_mobile_app_ads.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
// Send an event when ad loads.
// admob.events.dispatchAppEvent("adId", "1");
// handle your click with onClick="handleClick()"
handleClick = function() {
admob.log("click ad: call handleClick()"); // call a log to XCode console for debug
// Send an event when ad is clicked.
admob.events.dispatchAppEvent("eventName", "params"); //{action}|{action params}...
//magic goes here
//i think the click measure through this url
//and use jQuery get that send get method without callbacks
$.get("%%CLICK_URL_UNESC%%")
};
</script>
You have to wait a while like 30 mins then you will see the click stats in your DFP console.

Resources