我正在创建一个应用程序,我希望从用户那里获得分析.我试图使用Phonegap插件,但我没有运气试图实现它.
我想知道是否有可能通过将应用程序视为普通网页并将一些javascript放在我的页面的头部来获取Google Analytics.
有一个更好的方法吗?Phonegap Google Analytics比我想做的要好得多吗?
看看这个简单的购物车演示:
http://plnkr.co/edit/CHt2iNSRJAJ6OWs7xmiP?p=preview
用户可以选择素食和水果,它将被添加到购物车阵列中.添加水果/蔬菜的功能非常相似,我想将它组合成一个可以在两个组件之间共享的功能.
selectFruit: function(product){
var cart = this.cart
for(p in cart){
if (cart[p]["type"] == "fruit"){
console.log("We already got a fruit!, Let's remove " + cart[p]["name"] + " and add in " + product["name"]);
this.cart.$remove(cart[p])
}
}
console.log("Adding " + product.name + " to cart.");
var productName = product.name
var cartFruit = {name: product.name, type: 'fruit'}
this.cart.push(cartFruit)
}
selectVeggie: function(product){
var cart = this.cart
for(p in cart){
if (cart[p]["type"] == "veggie"){
console.log("We already got a veggie!, Let's remove " + …Run Code Online (Sandbox Code Playgroud) 我正在Postman上测试Uber API,我能够成功发送带有表单数据的请求.当我尝试使用Node.js和axios库转换此请求时,我收到错误.
这是我的Postman请求的样子:
我得到的回应是: { "error": "invalid_client" }
这是我在Node.js和axios中所做的事情:
var axios = require("axios");
const config = { headers: { 'Content-Type': 'multipart/form-data' } };
axios.post('https://login.uber.com/oauth/v2/token', {
client_id: '***',
client_secret: '***',
grant_type: 'authorization_code',
redirect_uri: 'http://localhost:8080/',
code: '***'
}, config)
.then(function(response) {
console.log(response.data)
})
.catch(function(error) {
console.log(error)
})
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到了400响应.
我添加了'multipart/form-data'标题,因为我在Postman请求中填写了表单数据.没有标题我得到相同的结果.
我期待从Postman得到相同的响应,我的Node.js脚本中的配置变量有问题吗?
任何帮助,将不胜感激!
我有一个简单的组件,当用户加载页面时调用一个动作,并且在该动作中,我试图调度另一个动作来将loggedIn商店的状态设置为true或false:
import React, { Component } from 'react'
import { Link, browserHistory } from 'react-router'
import $ from 'jquery'
class Login extends Component {
constructor(props) {
super(props)
}
componentDidMount() {
this.props.actions.guestLoginRequest()
}
render() {
return (
<div>
<div classNameName="container">
<div className="row">
We are signing you in as a guest
</div>
</div>
</div>
)
}
}
export default Login
Run Code Online (Sandbox Code Playgroud)
我可以在guestLoginRequest调用操作时获取登录信息,但是当我尝试在其中调度另一个操作时,没有任何反应:
guestLoginRequest: function(){
var ref = new Firebase("https://penguinradio.firebaseio.com");
ref.authAnonymously(function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} …Run Code Online (Sandbox Code Playgroud) 我正在使用Lyft API,并试图找出如何使用具有节点脚本的axios获取访问令牌.
我可以通过填写表格来手动获取访问令牌,如下所示:
当我填写表格时,我可以成功地从Lyft获得一个新令牌.
我试图通过执行以下操作将此转换为使用axios的POST请求:
var axios = require('axios');
var data = {
"grant_type": "client_credentials",
"scope": "public",
"client_id": "XXXXXXXXX",
"client_secret": "XXXXXXXX"
};
var url = "https://api.lyft.com/oauth/token";
return axios.post(url, data)
.then(function(response){
console.log(response.data)
})
.catch(function (error) {
console.log(error);
});
Run Code Online (Sandbox Code Playgroud)
当我运行脚本时,我收到此错误:
{ error_description: 'Unauthorized', error: 'invalid_client' }
Run Code Online (Sandbox Code Playgroud)
我的axios请求中缺少什么?任何帮助,将不胜感激!
我正在尝试按照Vue.js上的教程,但第一课的代码不适用于v-repeat.我正在尝试在tasks对象中显示数据:
<div id="tasks">
<div>
<h1>Tasks</h1>
<ul class="list-group">
<li v-repeat="task: tasks">
{{ task.body }}
</li>
</ul>
</div>
</div>
<script>
new Vue ({
el: '#tasks',
data: {
tasks: [
{ body: 'Go to store', completed: false }
]
}
})
</script>
Run Code Online (Sandbox Code Playgroud) 我正在尝试向我的应用添加指令,请在此处查看演示:
http://plnkr.co/edit/XlmS8wIuyrwYXXaXbdPr?p=preview
代码在浏览器(Chrome 33)上呈现,但控制台仍然会抛出错误:
Error: [$interpolate:interr] Can't interpolate:{{example_chart}}
TypeError: Converting circular structure to JSON
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么控制台抛出错误,同时还有其他一切成功?只是试图理解"为什么"即使代码似乎工作.
这是JS:
var myapp = angular.module('myapp', ["ui.router"])
myapp.config(function($stateProvider, $urlRouterProvider){
// For any unmatched url, send to /route1
$urlRouterProvider.otherwise("/route1")
$stateProvider
.state('route1', {
url: "/route1",
templateUrl: "route1.html"
})
.state('route1.list', {
url: "/list",
templateUrl: "route1.list.html",
controller: function($scope){
$scope.items = ["A", "List", "Of", "Items"];
}
})
.state('route2', {
url: "/route2",
templateUrl: "route2.html"
})
.state('route2.list', {
url: "/list",
templateUrl: "route2.list.html",
controller: function($scope){
$scope.things = ["A", "Set", "Of", "Things"];
}
})
}) …Run Code Online (Sandbox Code Playgroud) 我想在用户点击某个项目时将我的应用中的视频设置为"精选".我有一个动作创建者在调用时执行一个简单的console.log(),并且为了测试我调用它w/componentDidMount(),它工作正常.我有一个单独的VideoItem组件,我试图传递动作创建者,但我得到一个错误:TypeError: Cannot read property 'props' of undefined.我试图添加.bind(this)到我传递的动作的结尾,但它没有任何区别.
如果动作创建者在我调用时工作componentDidMount,为什么我不能将它传递给子组件?这是我的Video和VideoItem组件:
// Video.js
import React, { Component } from 'react'
import VideoItem from './VideoItem'
class Videos extends Component {
componentDidMount() {
this.props.actions.getVideos()
// This function works, but getting error
// when passing to VideoItem component
this.props.actions.setFeaturedVideo()
}
constructor(props) {
super(props);
}
render() {
if(this.props.videos.length == 0){
return <p>Loading....</p>
}
return (
<div className="container">
<ul className="row">
{this.props.videos.map(function(result) {
return (
<VideoItem
key={result.position}
setFeaturedVideo={this.props.setFeaturedVideo}
video={result}
/>
) …Run Code Online (Sandbox Code Playgroud) 我有一个原始比特币交易,我想用 Blockcypher API 广播,我使用 axios 发送 POST 请求:
var axios = require('axios')
axios.post('https://api.blockcypher.com/v1/bcy/test/txs/send', {
"tx": "010000000174770a05466c28df24425ac50dba86ead47af31778f01fa1069bf01816810a2b010000008b48304502210090c86f59c8df34979ccb485c524803e9ba1290cc4448cdbfdcc8f3cf3337102302202357e77439354acf7b178392720f433cfeac952d34098addb2eea7edcf7884c20141048520397beff2fe111c7af8aa42c99b317453b1595ec5c3b3cf9eb2059dd06b9b956165419d51a48d885aacb4df1004d7c93b30e2e53c6d4f64f9668c9fd7e92fffffffff02cd0d0000000000001976a914243170728a9278ed24b4ac7ba9df33bdadf7afd488ac00000000000000004d6a4b77723335322d33316472342d4e42412d33323132322d333435352d363933352d323334392d323334302d31323333322d39392d30322d31362d323031352d32336f6c2d313030303030303000000000"
})
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
在终端中运行时出现错误:
{ data: { error: 'Couldn\'t deserialize request: json: cannot unmarshal string into Go value of type pooch.JSONTx' }
Run Code Online (Sandbox Code Playgroud)
知道我的 POST 有什么问题吗?我试图用 tx 而不是“tx”发布,但它仍然不起作用。在文档上,他们建议这样做:
var pushtx = {
tx: "01000000011935b41d12936df99d322ac8972b74ecff7b79408bbccaf1b2eb8015228beac8000000006b483045022100921fc36b911094280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1df51a4c44f5ab0bc940c105045e2cc77e618044ffffffff0240420f00000000001976a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac20da3c00000000001976a914efec6de6c253e657a9d5506a78ee48d89762fb3188ac00000000"
};
$.post('https://api.blockcypher.com/v1/bcy/test/txs/push', JSON.stringify(pushtx))
.then(function(d) {console.log(d)});
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时,我收到错误:
TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)
所以我认为使用 axios 更容易,因为我至少得到了 Blockcypher 的回复。任何帮助将非常感激!
javascript ×8
axios ×3
node.js ×2
post ×2
reactjs ×2
redux ×2
vue.js ×2
angularjs ×1
bitcoin ×1
cordova ×1
flux ×1
highcharts ×1
json ×1
lyft-api ×1
oauth-2.0 ×1
react-redux ×1
reactjs-flux ×1
redux-thunk ×1
uber-api ×1