我不确定我这样做是否正确,任何建议都将不胜感激.
我有一个餐厅选择器,用户可以从中选择一家餐馆.然后所有其他子状态加载特定于所选餐厅的内容.但是我需要默认选择一个子状态,包括一个餐厅,根据用户最近的位置选择,或者如果他们之前选择了一个,则选择cookie数据.但是,我不知道如何在不知道餐馆ID的情况下我可以默认重定向到子状态?
下面我的代码的一个混合版本来说明.
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/restaurant/[some id based on cookie info]/our-food"); // if no id is set, then I want to get it from a cookie, but then how do i do the redirect?
$stateProvider
.state('restaurant', {
url: '/restaurant/:restaurantId',
template: "<ui-view/>",
controller: function($state, $stateParams, Data, RestaurantService, $cookieStore) {
if(typeof $stateParams.restaurantId !== 'undefined') {
// get the restaurantID from the cookie
}
}
})
.state('restaurant.our-food', {
url: '/our-food',
templateUrl: function($stateParams) {
return 'templates/food-food.html?restaurantId=' + $stateParams.restaurantId;
},
controller: 'SubNavCtrl'
}) …Run Code Online (Sandbox Code Playgroud) 我有嵌套状态,父状态和子状态具有单独的控制器.但只有父州才会被执行.
我有网址结构:#/ restaurant/2 /我们的食物
因此,我希望它加载ID为2的餐厅,然后儿童控制器加载"我们的食物"内容并处理其他一些功能.
我的代码是:
var app = angular.module("app", ['ui.router']);
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider
.state('home', {
url: '/',
controller: function($scope, $stateParams) {
$scope.setRestaurant(0);
}
})
.state('restaurant', {
url: '/restaurant/:restaurantId',
controller: function($scope, $stateParams, $state) {
console.log('first');
if($stateParams.restaurantId > 0) {
$scope.setRestaurant($stateParams.restaurantId);
}
else {
$state.go('home');
}
}
})
.state('restaurant.our-food', {
url: '/our-food',
templateUrl: 'templates/our-food.html',
controller: function() {
console.log('second');
}
});
Run Code Online (Sandbox Code Playgroud)
});
我正在使用 google-api-php-client 从客户端 0auth 流请求访问令牌,但它返回错误“无法从请求确定客户端 ID”。
我的代码如下。
我的 client_secret.json:
"web": {
"client_id":"123",
"project_id":"1234",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"123456789",
"redirect_uris":[
"http://localhost:7777/v1/oauth2callback"
],
"javascript_origins":[
"http://localhost:7777"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我的身份验证 URL 创建:
$client->setAuthConfig(base_path() . '/client_secret.json');
$client->addScope(\Google_Service_Calendar::CALENDAR);
$client->setRedirectUri(URL::to('/') . '/v1/oauth2callback');
$client->setAccessType('offline');
$client->setPrompt('consent');
$client->setIncludeGrantedScopes(true);
$url = $client->createAuthUrl();
print filter_var($url, FILTER_SANITIZE_URL);
Run Code Online (Sandbox Code Playgroud)
然后我手动转到 URL:
身份验证流程似乎一切正常,并将我返回到我尝试解码令牌的网址:
$code = $request->code;
$client = new Google\Client();
$accessToken = $client->fetchAccessTokenWithAuthCode($code);
var_dump($accessToken);
exit;
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误:
array(2) { ["error"]=> string(15) "invalid_request" ["error_description"]=> string(43) "无法根据请求确定客户端 ID。" }
google-api google-api-client google-oauth google-api-php-client