I trying to register c2dm, but allways give me this error:
05-18 10:48:32.357: D/C2DMRegistrar(225): [C2DMRegistrar.46] register: http error 400
this is the register method:
public static final String EXTRA_SENDER = "sender";
public static final String EXTRA_APPLICATION_PENDING_INTENT = "app";
public static final String REQUEST_UNREGISTRATION_INTENT = "com.google.android.c2dm.intent.UNREGISTER";
public static final String REQUEST_REGISTRATION_INTENT = "com.google.android.c2dm.intent.REGISTER";
public static final String LAST_REGISTRATION_CHANGE = "last_registration_change";
public static final String BACKOFF = "backoff";
// public static final String GSF_PACKAGE = "com.google.android.gsf";
public static void register(Context context, String senderId) {
Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
// registrationIntent.setPackage(GSF_PACKAGE);
registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
PendingIntent.getBroadcast(context, 0, new Intent(), 0));
registrationIntent.putExtra(EXTRA_SENDER, senderId);
context.startService(registrationIntent);
}
I test it with GSF_PACKAGE, and without GSF_PACKAGE.
SenderId is a mail acount XXXX#XXX.com, and I received a mail like this:
From: noreply#google.com [mailto:noreply#google.com]
Thank you for your interest in Android Cloud to Device Messaging (C2DM).
We've accepted your application into the trial group. The Google account
you requested as the sender account for your application:
XXXX#XXX.com
I´m in AVD emulator, and i have a google account in emulator too. And in real mobile, same thing.
I don´t receive any call in C2DMBaseReceiver.onHandleIntent, only show that error.
Any idea?
Have you set Your Google account through your Emulator, if not do so by Settings-> Account& Sync-> Add an account
Hope this helps !!!
Related
i did not really like to take your time for my problem, but after 1 week of searching about registration code of Asmack, i ended up with try/fail on the clues,because there is extacly non simple of that on net, here is my code:
public class Registration extends IQ {
public static final String HOST = "http://127.0.0.1";
public static final int PORT = 9090;
public static final String SERVICE = "what is this?!";
public static final String USERNAME = "reza";
public static final String PASSWORD = "mypassword";
XMPPConnection connection;
public void create() {
ConnectionConfiguration connConfig =
new ConnectionConfiguration(HOST,PORT, SERVICE);
connection = new XMPPConnection(connConfig);
connection.connect();
AccountManager am = new AccountManager(connection);
Map<String, String> mp = new HashMap<String, String>();
// adding or set elements in Map by put method key and value
// pair
mp.put("username", USERNAME);
mp.put("password", PASSWORD);
// am.createAccount(mConfig.userName, mConfig.password);
am.createAccount(USERNAME, PASSWORD, mp);
}
#Override
public CharSequence getChildElementXML() {
// TODO Auto-generated method stub
return null;
}
}
but it returns error in codding can not instantiate the type XMPPConnection and the constructor AccountManager is not visible, can you help me with the code, and also i have questions what is service in the connection configuration and what is the CharSequence getChildElementXML() for? thanks alot, if you could lead me to an android smack definitive guide, that would best best thing some one did for me in past 20years , also this could be a guide for any one else who searching to learn like me ;)
If you are using openfire on server side then you can use userservice plugin there.
Using this plugin you can hit http or https web service to register the user or deactivate the user.
I am in a Android project of creating a Google Reader client.
I with to use built in account credential and to be as close of the official google reader app on that point.
I'm struggling in a problem since a week and can't find out how to solve it.
I managed to get an Auth Token from AccountManager using authtokentype "reader".
The token is of the form
DQAAAOcAAACJAmAkHEpPnaP-v7HxPYyz3XtCNwTiFLUsqYXfLQvCko4AqUyY213U81fXeNZC3VVArBaEsJJFcRXDmczrEhDquxiJiWSp7eM9T8Bs2VV3uqFwE7irrfarKyBH-oVn2nZxKc3wcugqa7k3p4KCotz48cQRslDQhSZj1AK4hxqO2eu5X8lutffRCPjA6kmgmXhkYA4RuTCxVXbZr0E_ytQteX2VzOlPbqrZ7QD7NiqbeJYODE3pk4BNjHTWtgXAr3J0U7LMdtRh9aC9AJoBp1SNl3jptyzqFfeEjWtVTBQlKtn40vyzMDt0sZoSIaSPquc
Now that I have the token, how do I login with the unofficial Google Reader api ?
I know this java api, and found various documentation here, here and here. All of these only lay the emphasis upon Client Login with email and password. Each time I find a code sample it is of the form
token = someFunctionIAlreadyUse();
someUndocumentedUnknowPersonalFunction(token);
Am I missing a simple way ? If not where can I find a detailled way of accessing the api (in java) ?
Just finding out how to do. The token given by android is the same as the token used in the regular google reader authentication. Here is some code from Christian Dadswell using Jsoup and modified to work with the Android authtoken :
public static String getGoogleToken(String authKey) throws UnsupportedEncodingException, IOException
{
Document doc = Jsoup.connect(_TOKEN_URL).header("Authorization", _AUTHPARAMS + authKey).userAgent(_USER_AGENT).timeout(4000).get();
// RETRIEVES THE RESPONSE TOKEN
String _TOKEN = doc.body().text();
return _TOKEN;
}
and
public static String getUserInfo(String authKey) throws UnsupportedEncodingException, IOException
{
Document doc = Jsoup.connect(_USER_INFO_URL).header("Authorization", _AUTHPARAMS + authKey).userAgent(_USER_AGENT).timeout(4000).get();
// RETRIEVES THE RESPONSE USERINFO
String _USERINFO = doc.body().text();
return _USERINFO;
}
And constants :
private static String _USER_AGENT = "YourAppNameHere";
private static final String _AUTHPARAMS = "GoogleLogin auth=";
private static final String _GOOGLE_LOGIN_URL = "https://www.google.com/accounts/ClientLogin";
private static final String _READER_BASE_URL = "http://www.google.com/reader/";
private static final String _API_URL = _READER_BASE_URL + "api/0/";
private static final String _TOKEN_URL = _API_URL + "token";
private static final String _USER_INFO_URL = _API_URL + "user-info";
private static final String _USER_LABEL = "user/-/label/";
private static final String _TAG_LIST_URL = _API_URL + "tag/list";
private static final String _EDIT_TAG_URL = _API_URL + "tag/edit";
private static final String _RENAME_TAG_URL = _API_URL + "rename-tag";
private static final String _DISABLE_TAG_URL = _API_URL + "disable-tag";
private static final String _SUBSCRIPTION_URL = _API_URL + "subscription/edit";
private static final String _SUBSCRIPTION_LIST_URL = _API_URL + "subscription/list";
I'm working on a multi-user Android application that provides to its users access to GMaps (find one another), chat and so on. Users should login to application using their accounts on Twitter, Facebook, Google+ etc. Everything works fine with all accounts except G+ - application can get access to G+ API only with its owner account. With other accounts I receive com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found or "authorization error". App is registered on the API Console, and OAuth2.0 authentication used. I use standard authentication mechanism from Google sites. Is it possible to use different G+ accounts to login?
Here is my code (Android v1.6):
public class GooglePlusActivity extends Activity {
public static final String LOG_TAG = GooglePlusActivity.class.getSimpleName();
public static final String EXTRA_FIRSTNAME = "firstname";
public static final String EXTRA_LASTNAME = "lastname";
public static final String EXTRA_NICKNAME = "nickname";
public static final String EXTRA_SEX = "sex";
public static final String EXTRA_AVATAR = "avatar";
public static final String EXTRA_ID_SOCNET = "id_socnet";
private ApplicationSettings mSettings;
private Person mProfile;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSettings = ((TomskApplication)getApplication()).getSettings();
signIn();
}
private void signIn() {
WebView webView = new WebView(this);
setContentView(webView);
webView.getSettings().setJavaScriptEnabled(false);
String googleAuthorizationRequestUrl = new GoogleAuthorizationRequestUrl(
mSettings.getGPID(), mSettings.getGPRedirectURI(),
mSettings.getGPScope()).build();
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if (url.startsWith(mSettings.getGPRedirectURI())) {
try {
Intent res_intent = new Intent();
if (url.indexOf("code=") != -1) {
String code = url.substring(mSettings
.getGPRedirectURI().length() + 7, url
.length());
AccessTokenResponse token = new GoogleAuthorizationCodeGrant(
new NetHttpTransport(),
new JacksonFactory(), mSettings.getGPID(),
mSettings.getGPSecret(), code, mSettings
.getGPRedirectURI()).execute();
mSettings.setGPToken(token);
// Loading user data
retrieveProfile();
if (mProfile == null) {retrieveProfile();}
res_intent.putExtra(EXTRA_FIRSTNAME, mProfile
.getName().getGivenName());
res_intent.putExtra(EXTRA_LASTNAME, mProfile
.getName().getFamilyName());
res_intent.putExtra(EXTRA_NICKNAME,
mProfile.getNickname());
res_intent.putExtra(EXTRA_SEX, mProfile.getGender());
res_intent.putExtra(EXTRA_AVATAR, mProfile
.getImage().getUrl());
res_intent.putExtra(EXTRA_ID_SOCNET, mProfile.getId());
setResult(Activity.RESULT_OK, res_intent);
view.setVisibility(View.INVISIBLE);
finish();
} else if (url.indexOf("error=") != -1) {
view.setVisibility(View.INVISIBLE);
setResult(Activity.RESULT_CANCELED);
finish();
}
} catch (IOException e) {
Log.d(LOG_TAG, e.toString());
}
return true;
} else {
return false;
}
}
});
webView.loadUrl(googleAuthorizationRequestUrl);
}
/**
* Retrieve user profile
*/
private void retrieveProfile() throws IOException {
JsonFactory jsonFactory = new JacksonFactory();
HttpTransport transport = new NetHttpTransport();
AccessTokenResponse token = mSettings.getGPToken();
GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(
token.accessToken, transport, jsonFactory,
mSettings.getGPID(), mSettings.getGPSecret(),
token.refreshToken);
Builder b = Plus.builder(transport, jsonFactory)
.setApplicationName("MyApp/1.0");
b.setHttpRequestInitializer(accessProtectedResource);
Plus plus = b.build();
mProfile = plus.people().get("me").execute();
}
}
I've searched on Google sites, Stack Overflow but found nothing. Please help.
Dont know that this will help but, if you are desperate....
New release of some of the Android client side libs on 4/4/2012 here
and there is fresh Google+ sample, using some reconfigured classes in the main() method where they access protected resources. The new version in R 1.8 is different than your code , at least at the top of the stack.... IMO the use in the new example of the Credential class and of the PLUS.Builder is probably going to boil down to pretty much the same implementation that you already have. You may want to look at the newer sample if you cannot get anything else to work.
new code from googlePlus sample in 1.8
public static void main(String[] args) {
try {
try {
// authorization
Credential credential = OAuth2Native.authorize(
HTTP_TRANSPORT, JSON_FACTORY, new LocalServerReceiver(),
Arrays.asList(PlusScopes.PLUS_ME));
// set up global Plus instance
plus = Plus.builder(HTTP_TRANSPORT, JSON_FACTORY)
.setApplicationName("Google-PlusSample/1.0").setHttpRequestInitializer(credential)
.build();
older code here
I want to make an android app which will update status in twitter.
I am using signpost-core-1.2.1.1 and signpost-commonshttp4-1.2.1.1 jar files.I have given internet uses permission and i have registered app in twitter giving read,write and direct messages permission. Also filled up the callback Url.But retrieveRequestToken() function throws OAuthCommunicationException.
code snippet:
private static final String CALLBACK_URI = "app://twitter";
private static final String REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token";
private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize";
String CONSUMER_KEY = "I4bwezijxf6VwpU8x0tygg";
String CONSUMER_SECRET = "Y6vSdZs3zWBrNogXZWSHKZ590RSXqB5wBwj8vFaayk";
private static CommonsHttpOAuthConsumer consumer;
private static CommonsHttpOAuthProvider provider;
consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
provider = new DefaultOAuthProvider(REQUEST_TOKEN_URL,ACCESS_TOKEN_URL, AUTHORIZE_URL);
String authUrl="";
authUrl = provider.retrieveRequestToken(consumer,CALLBACK_URI);
I am totally stuck with this.Please reply.
Your consumer credentials are working fine in my test twitter app, so could not find the issue with you.
Here is the complete detailed article on Twitter integration and you can literally copy the code of TwitterConnectWebActivity in your app and call it by an intent for twitter integration.Twitter integration in Android app complete codeThis must solve your problem.
I want to make an android app which will update status in twitter.
I am using signpost-core-1.2.1.1 and signpost-commonshttp4-1.2.1.1 jar files.I have given internet uses permission and i have registered app in twitter giving read,write and direct messages permission. Also filled up the callback Url.
code snippet:
private static final String CALLBACK_URI = "app://twitter";
private static final String REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token";
private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize";
String CONSUMER_KEY = "XXXXXXXXXX";
String CONSUMER_SECRET = "XXXXXXXXXX";
private static CommonsHttpOAuthConsumer consumer;
private static CommonsHttpOAuthProvider provider;
consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
provider = new DefaultOAuthProvider(REQUEST_TOKEN_URL,ACCESS_TOKEN_URL, AUTHORIZE_URL);
String authUrl="";
authUrl = provider.retrieveRequestToken(consumer,CALLBACK_URI);
I am totally stuck with this.Please reply.
Signpost documentation says DefaultOAuthProvider has some problem with Android implementation of java.net. They suggest use of CommonsHttpOAuthProvider instead. I was having the same problem. This solved this exception in my case. Hope this helps.
First By android application we are not allowed to send callbackurl, so use "oob" instead of callbackurl, and there is an api for twitter which is also supported on android, it is jTwitter.