我想在我的cakePHP应用程序中使用Google OAuth,让用户使用他们的Google帐户登录.我查看了以下组件:http://code.42dh.com/oauth/.不知何故,我无法让它起作用.我不知道我做错了什么.我在Google注册表上注册了我的申请,并获得了我的消费者密钥和消费者密钥.我在消费者组件中添加了它.我仍然没有得到它的工作.
这是我的代码:
<?php
class ExampleController extends AppController {
public $uses = array();
var $helpers = array('Javascript', 'Ajax');
public $components = array('OauthConsumer');
public function google() {
$scope = "https://www.google.com/m8/feeds/";
$REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken?scope=' . urlencode($scope);
$requestToken = $this->OauthConsumer->getRequestToken('Google', $REQUEST_TOKEN_URL, 'http://mydomain.com/example/google_callback');
$this->Session->write('google_request_token', $requestToken);
$this->redirect('https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=' . $requestToken->key);
}
public function google_callback() {
$requestToken = $this->Session->read('google_request_token');
$accessToken = $this->OauthConsumer->getAccessToken('Google', 'https://www.google.com/accounts/OAuthGetAccessToken', $requestToken);
}
}
?>
Run Code Online (Sandbox Code Playgroud)
当我尝试请求requestToken时,我得到了答案:"签名无效".
有人在他们的cakePHP应用程序中使用Google OAuth,是否愿意给我一些提示?
我想将a转换System.Type为Generic Type定义,因此我可以使用它来调用Generic方法.基本上是相反的typeof.
示例(我使用"classof",我需要真正的解决方案,以便您看到我遇到问题的地方,因为classof不是真正的.NET方法):
public class BaseAppContext {
private Type settingsType;
public Type SettingsType
{
get { return this.settingsType; }
set { this.SettingsType = value; }
}
public void MyFunction() {
MyStaticClass.GetData<classof(this.SettingsType)>();
}
}
Run Code Online (Sandbox Code Playgroud)
更多信息为什么我使用这种奇怪的方式来处理问题.BaseAppContext是一个由许多其他类引用的类.如果我愿意使它成为通用,这将意味着代码的许多其他部分将改变,这是我不想要的.我正在编写一个框架,所以我希望框架能够输入一次类型,开发人员只需使用提供的函数,而无需在每次尝试调用方法时处理类型.
我正在尝试构建一个 C# dotnetcore 控制台应用程序来与使用 OAuth2 进行授权的 api 进行交互。我还没有完全弄清楚如何将其用于 C# 控制台应用程序,甚至是不打算让用户登录的库。这可能吗?
到目前为止我得到的是以下内容:
private static string _auth_url = "https://idp.bexio.com/authorize";
private static string _token_url = "https://idp.bexio.com/token";
private static string _callback_url = "https://www.myurl.com";
private static string _scope = "monitoring_show";
private static string _client_id = "myid";
private static string _client_secret = "mysecret";
static void Main(string[] args)
{
//request token
var restclient = new RestClient(_auth_url);
RestRequest request = new RestRequest("request/oauth") {Method = Method.POST};
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("client_id", _client_id);
request.AddParameter("client_secret", _client_secret);
request.AddParameter("grant_type", "client_credentials");
var tResponse = …Run Code Online (Sandbox Code Playgroud) 我们正在为一个高效的网站评估一些PHP框架.CakePHP看起来很有趣,但我们不知道它是否符合我们的需求.
基本上,当您查看CakePHP的文档和教程时,它看起来非常有前景.然而到目前为止,总有一些东西让我对框架产生了麻烦,也许已经在生产项目中使用CakePHP的人可以为我回答这个问题?
我总是想知道在某个外键的历史表中找到最后一个条目的正确方法是什么?
例:
我们假设我们有一个这样的表:
tHistory(ID | FK_User |状态|时间戳)
在Oracle中读取每个FK_User ID的lates条目的正确方法是什么?我总是使用一个subselect为此,但它看起来不对我...任何其他方法这样做?
我需要一个 Nullable 类型,但如何初始化这样的变量?每当我尝试这样做时,它会自动转换为普通的 Int32。
Nullable<Int32> nullableInt32 = new Nullable<Int32>(3);
Console.WriteLine(nullableInt32.GetType()); // gives me System.Int32
Run Code Online (Sandbox Code Playgroud)
这是一个错误吗?我怎样才能真正初始化 Nullable?
我使用条形码进行扫描应用程序。所有扫描的页面都需要检查条形码。由于条形码始终位于同一位置,我可以裁剪该区域以加快处理速度。问题是,只有部分扫描的页面中有条形码。其他人则没有。
现在,在有条形码的页面上应该很容易找到条形码,因为这些页面仅包含此 Code128,否则就是一张普通的白纸。我可以设置任何选项来加快该过程吗?顺便说一句,TryHarder-Flag 已设置为 false。
有人有想法吗?