想要在Google任务上推进一些任务。 [英] Wanted to push some tasks on Google tasks.

查看:68
本文介绍了想要在Google任务上推进一些任务。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 DotNetOpenAuth.OAuth2;
使用 Limilabs.Client.Authentication.Google;
使用 Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
使用 System.Diagnostics;
使用 System.Net;
使用 System.Text;
使用 Google.Apis.Tasks.v1;
使用 Google.Apis.Authentication.OAuth2;


public partial class NewDefault:System.Web.UI.Page
{
List< string>范围;

const string clientID = 518958397819.apps.googleusercontent.com;
const string clientSecret = HyNMCbxvC5GkK-aIZIuDsq4X;

public const string OutOfBandCallbackUrl = http:// localhost:1500 / new_google_tasks / NewDefault.aspx;
受保护 void Page_Load( object sender,EventArgs e)
{
AuthorizationServerDescription server1 = new AuthorizationServerDescription
{
AuthorizationEndpoint = new Uri( https://accounts.google.com/o/oauth2 / auth),
TokenEndpoint = new Uri( https://accounts.google.com/o/oauth2/token),
ProtocolVersion = ProtocolVersion.V20,
// RedirectUri =http:// localhost:1500 / new_google_tasks / NewDefault.aspx
// OutOfBandC allbackUrl =;
};

List< string> scope = new 列表< string>
{
https://www.googleapis.com/auth/tasks

};

if (Request.QueryString.Count > 0
{
if (!string.IsNullOrEmpty(Request.QueryString [ code]))
{
WebServerClient consumer = new WebServerClient(server1,clientID,clientSecret);
consumer.ClientIdentifier = clientID;
consumer.ClientSecret = clientSecret;
// consumer.ClientCredentialApplicator =
// ClientCredentialApplicator.PostParameter(clientSecret);
IAuthorizationState grantedAccess = consumer.ProcessUserAuthorization();

string accessToken = grantedAccess.AccessToken;

会话[ AccessToken] = accessToken;
HttpWebRequest request =(HttpWebRequest)WebRequest.Create( https://www.googleapis.com/tasks / v1 / users / @ me / lists?key = + accessToken);
ASCIIEncoding encoding = new ASCIIEncoding();

request.Method = 发布;
request.Headers.Add( 授权 Bearer + grantedAccess.AccessToken);

HttpWebResponse response =(HttpWebResponse)request.GetResponse();
GoogleApi api = new GoogleApi(accessToken);
}
}
else
{
WebServerClient consumer = new WebServerClient(server1,clientID,clientSecret);

consumer.RequestUserAuthorization(范围, online new Uri( http:// localhost:1500 / new_google_tasks / NewDefault。 ASPX));


WebServerClient consumer1 = new WebServerClient(server1,clientID,clientSecret);
}
}
}





在线上获取错误

 HttpWebResponse response =(HttpWebResponse)request.GetResponse(); 





即远程服务器返回错误:(411)所需长度。





我正在处理谷歌任务。 PLZ帮助我弄错了。

解决方案

@Tadit Dash现在得到不同的错误

远程服务器返回错误:(403)禁止的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.OAuth2;
using Limilabs.Client.Authentication.Google;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using System.Diagnostics;
using System.Net;
using System.Text;
using Google.Apis.Tasks.v1;
using Google.Apis.Authentication.OAuth2;


public partial class NewDefault : System.Web.UI.Page
{
    List<string> scope;

    const string clientID = "518958397819.apps.googleusercontent.com";
    const string clientSecret = "HyNMCbxvC5GkK-aIZIuDsq4X";

    public const string OutOfBandCallbackUrl = "http://localhost:1500/new_google_tasks/NewDefault.aspx";
    protected void Page_Load(object sender, EventArgs e)
    {
        AuthorizationServerDescription server1 = new AuthorizationServerDescription
        {
            AuthorizationEndpoint = new Uri("https://accounts.google.com/o/oauth2/auth"),
            TokenEndpoint = new Uri("https://accounts.google.com/o/oauth2/token"),
            ProtocolVersion = ProtocolVersion.V20,
            //RedirectUri = "http://localhost:1500/new_google_tasks/NewDefault.aspx"
            //OutOfBandCallbackUrl = "";
        };

        List<string> scope = new List<string> 
        { 
            "https://www.googleapis.com/auth/tasks"
 
        };

        if (Request.QueryString.Count > 0)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                WebServerClient consumer = new WebServerClient(server1, clientID, clientSecret);
                consumer.ClientIdentifier = clientID;
                consumer.ClientSecret = clientSecret;
                //consumer.ClientCredentialApplicator =
                //    ClientCredentialApplicator.PostParameter(clientSecret);
                IAuthorizationState grantedAccess = consumer.ProcessUserAuthorization(null);

                string accessToken = grantedAccess.AccessToken;

                Session["AccessToken"] = accessToken;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/tasks/v1/users/@me/lists?key=" + accessToken);
                ASCIIEncoding encoding = new ASCIIEncoding();

                request.Method = "Post";
                request.Headers.Add("Authorization", "Bearer " + grantedAccess.AccessToken);

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                GoogleApi api = new GoogleApi(accessToken);
            }
        }
        else
        {
            WebServerClient consumer = new WebServerClient(server1, clientID, clientSecret);

            consumer.RequestUserAuthorization(scope, "online", new Uri("http://localhost:1500/new_google_tasks/NewDefault.aspx"));


            WebServerClient consumer1 = new WebServerClient(server1, clientID, clientSecret);
        }
    }   
}



Getting error on line

HttpWebResponse response = (HttpWebResponse)request.GetResponse();



i.e The remote server returned an error: (411) Length Required.



I m working on google tasks. plz help me to get my mistake.

解决方案

@Tadit Dash now getting different error
The remote server returned an error: (403) Forbidden.


这篇关于想要在Google任务上推进一些任务。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆