Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:37:46+00:00 2026-06-06T19:37:46+00:00

Guyz facing problems with creating a push notification service (for android) using Google C2DM

  • 0

Guyz facing problems with creating a push notification service (for android) using Google C2DM which uses OAuth 2.0 . I am sort of newbie dev , and the deadline is on the head ! Please help !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:37:47+00:00Added an answer on June 6, 2026 at 7:37 pm

    In the above question there was only one issue . I had lost my cool and was into tremendous pressure. This doesn’t work well with intellectual property. So , with a bit of mental peace above simple issue was solved.
    Guyz below given is the code for the dummies like me :

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net;
    using System.Text;
    using System.IO;
    using System.Collections;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.Collections.Specialized;
    using System.Diagnostics;
    using System.Configuration;
    using System.Web.Script.Serialization;
    using PushNotification.Entities;
    namespace PushNotification
    {
        public class AndroidCommunicationService
        {
    
            public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
            {
                return true;
            }
    
            public string GetAuthenticationCode()
            {
                string returnUrl = "";
                string URL = "https://accounts.google.com/o/oauth2/auth";
                NameValueCollection postFieldNameValue = new NameValueCollection();
                postFieldNameValue.Add("response_type", "code");
                postFieldNameValue.Add("scope", "https://android.apis.google.com/c2dm/send");
                postFieldNameValue.Add("client_id", ConfigurationManager.AppSettings["ClientId"].ToString());
                postFieldNameValue.Add("redirect_uri", "http://localhost:8080/TestServer/test");
                postFieldNameValue.Add("state", "profile");
                postFieldNameValue.Add("access_type", "offline");
                postFieldNameValue.Add("approval_prompt", "auto");
                postFieldNameValue.Add("additional_param", DateTime.Now.Ticks.ToString());
                string postData = GetPostStringFrom(postFieldNameValue);
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    
                HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
                Request.Method = "POST";
                Request.KeepAlive = false;
    
                Request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                Request.ContentLength = byteArray.Length;
    
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
                Stream dataStream = Request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
    
                Request.Method = "POST";
    
                try
                {
                    WebResponse Response = Request.GetResponse();
    
                    var sr = new StreamReader(Response.GetResponseStream());
                   // You can do this and return the content on the screen ( I am using MVC )
                    returnUrl = sr.ReadToEnd();
                  // Or 
                    returnUrl = Response.RedirectUri.ToString();
                }
                catch
                {
                    throw ;
                }
                return returnUrl;
            }
            public TokenResponse GetNewToken(string Code)
            {
                TokenResponse tokenResponse = new TokenResponse();
                string URL = ConfigurationManager.AppSettings["TokenCodeUrl"];
                NameValueCollection postFieldNameValue = new NameValueCollection();
                postFieldNameValue.Add("code", Code);
                postFieldNameValue.Add("client_id", ConfigurationManager.AppSettings["ClientId"]);
                postFieldNameValue.Add("client_secret", ConfigurationManager.AppSettings["ClientSecret"]);
                postFieldNameValue.Add("redirect_uri", ConfigurationManager.AppSettings["RedirectUrl"]);
                postFieldNameValue.Add("grant_type", "authorization_code");
    
                string postData = GetPostStringFrom(postFieldNameValue);
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    
                HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
                Request.Method = "POST";
                Request.KeepAlive = false;
    
                Request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                Request.ContentLength = byteArray.Length;
    
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
                Stream dataStream = Request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
    
                Request.Method = "POST";
    
                try
                {
                    WebResponse Response = Request.GetResponse();
                    var tokenStreamRead = new StreamReader(Response.GetResponseStream());
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    var objText = tokenStreamRead.ReadToEnd();
                     tokenResponse = (TokenResponse)js.Deserialize(objText, typeof(TokenResponse));            
                }
                catch (WebException wex)
                {
                    var sr = new StreamReader(wex.Response.GetResponseStream());
    
                    Exception ex = new WebException(sr.ReadToEnd() + wex.Message);
                    throw ex;
                }
    
                return tokenResponse;
            }
    
            public TokenResponse RefreshToken(string RefreshToken)
            {
                TokenResponse tokenResponse = new TokenResponse();
                string URL = ConfigurationManager.AppSettings["TokenCodeUrl"]; 
                NameValueCollection postFieldNameValue = new NameValueCollection();
                postFieldNameValue.Add("refresh_token", RefreshToken);
                postFieldNameValue.Add("client_id", ConfigurationManager.AppSettings["ClientId"]);
                postFieldNameValue.Add("client_secret", ConfigurationManager.AppSettings["ClientSecret"]);
                postFieldNameValue.Add("grant_type", "refresh_token");
    
                string postData = GetPostStringFrom(postFieldNameValue);
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    
                HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
                Request.Method = "POST";
                Request.KeepAlive = false;
    
                Request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                Request.ContentLength = byteArray.Length;
    
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
                Stream dataStream = Request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
    
                Request.Method = "POST";
    
                try
                {
                    WebResponse Response = Request.GetResponse();
                    var tokenStreamRead = new StreamReader(Response.GetResponseStream());
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    var objText = tokenStreamRead.ReadToEnd();
                    tokenResponse = (TokenResponse)js.Deserialize(objText, typeof(TokenResponse));
                }
                catch 
                {
                    throw;
                }
    
                return tokenResponse;
            }
    
            public string SendPushMessage(string RegistrationId, string Message ,string AuthString)
            {
                HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["PushMessageUrl"]);
                Request.Method = "POST";
                Request.KeepAlive = false;
    
                //-- Create Query String --//
                NameValueCollection postFieldNameValue = new NameValueCollection();
                postFieldNameValue.Add("registration_id", RegistrationId);
                postFieldNameValue.Add("collapse_key", "fav_Message");
                postFieldNameValue.Add("data.message", Message);
                postFieldNameValue.Add("additional_value", DateTime.Now.Ticks.ToString());
    
                string postData = GetPostStringFrom(postFieldNameValue);
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    
    
                Request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                Request.ContentLength = byteArray.Length;
    
    
    // This is to be sent as a header and not as a param .
                Request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + AuthString);
    
    
    
    
    
                try
                {
                    //-- Create Stream to Write Byte Array --// 
                    Stream dataStream = Request.GetRequestStream();
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Close();
    
                    ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
                    WebResponse Response = Request.GetResponse();
                    HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
    
                    if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
                    {
                        return "Unauthorized - need new token";
                    }
                    else if (!ResponseCode.Equals(HttpStatusCode.OK))
                    {
                        return "Response from web service isn't OK";
    
                    }
    
                    StreamReader Reader = new StreamReader(Response.GetResponseStream());
                    string responseLine = Reader.ReadLine();
                    Reader.Close();
    
                    return responseLine;
    
                }
                catch 
                {
    
                    throw;
                }
    
    
            }
    
            private string GetPostStringFrom(NameValueCollection postFieldNameValue)
            {
                //throw new NotImplementedException();
                List<string> items = new List<string>();
    
                foreach (String name in postFieldNameValue)
                    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(postFieldNameValue[name])));
    
                return String.Join("&", items.ToArray());
            }
            private static bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
            {
                return true;
            }
    
        }
    }
    public class TokenResponse
        {
            public String access_token{ get; set; }
    
            public String expires_in { get; set; }
    
            public String token_type { get; set; }
    
            public String refresh_token { get; set; }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI Guyz i have created a sectioned custom listview using baseadapter its working fine
hi guyz i know android says if u are working with gui adjust your
hi guyz i saw and tried the code using scaletransform from andrej blog on
hai guyz, how can i send AT-command through bluetooth from a python application? OS:fedora
Would you guyz be so kind to help me with such question: I have
I am building a client server application using Java Sockets (in Windows XP). For
I have process which continuously downloads XML from the feed and saves it to
Hey guyz i am a newbie in Yii framework. I want to remove the
Hi guyz I'm trying to implement the InnerFade JQuery on my page but I'm
I'm building a cash management software using WPF for learning purposes, and I'm having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.