not much done, however im alot closer to haveing twitter intergration finished.
i have made a java se twitter app to learn the api, and started the porting over to android. right now the issue im having is that the onActivityResult() is not being called at the right time.
This commit is contained in:
@@ -3,8 +3,6 @@
|
|||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="src" path="gen"/>
|
<classpathentry kind="src" path="gen"/>
|
||||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
<classpathentry kind="src" path="FacebookLib_src"/>
|
<classpathentry kind="lib" path="libs/twitter4j-core-2.1.11.jar"/>
|
||||||
<classpathentry kind="lib" path="libs/jtwitter.jar"/>
|
|
||||||
<classpathentry kind="lib" path="libs/signpost-core-1.2.1.1.jar"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -30,11 +30,4 @@
|
|||||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
<linkedResources>
|
|
||||||
<link>
|
|
||||||
<name>FacebookLib_src</name>
|
|
||||||
<type>2</type>
|
|
||||||
<locationURI>_android_FacebookLib_9c84f9bf/src</locationURI>
|
|
||||||
</link>
|
|
||||||
</linkedResources>
|
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<service android:process=":TravelPostLocationService" android:enabled="true" android:name="LocationService" android:exported="true"></service>
|
<service android:process=":TravelPostLocationService" android:enabled="true" android:name="LocationService" android:exported="true"></service>
|
||||||
<activity android:name="WebAuth"></activity>
|
<activity android:name="WebAuth" android:launchMode="singleInstance" android:configChanges="orientation"></activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="7" />
|
<uses-sdk android:minSdkVersion="7" />
|
||||||
|
|||||||
@@ -9,4 +9,4 @@
|
|||||||
|
|
||||||
# Project target.
|
# Project target.
|
||||||
target=Google Inc.:Google APIs:9
|
target=Google Inc.:Google APIs:9
|
||||||
android.library.reference.1=../FacebookLib/
|
proguard.config=proguard.cfg
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ public final class R {
|
|||||||
public static final class attr {
|
public static final class attr {
|
||||||
}
|
}
|
||||||
public static final class drawable {
|
public static final class drawable {
|
||||||
public static final int facebook_icon=0x7f020000;
|
public static final int icon=0x7f020000;
|
||||||
public static final int icon=0x7f020001;
|
|
||||||
}
|
}
|
||||||
public static final class id {
|
public static final class id {
|
||||||
public static final int authCode=0x7f060002;
|
public static final int authCode=0x7f060002;
|
||||||
@@ -21,9 +20,8 @@ public final class R {
|
|||||||
public static final int widgetbutton=0x7f060000;
|
public static final int widgetbutton=0x7f060000;
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int main=0x7f030000;
|
public static final int travelpostwidget=0x7f030000;
|
||||||
public static final int travelpostwidget=0x7f030001;
|
public static final int webauth=0x7f030001;
|
||||||
public static final int webauth=0x7f030002;
|
|
||||||
}
|
}
|
||||||
public static final class string {
|
public static final class string {
|
||||||
public static final int app_name=0x7f050001;
|
public static final int app_name=0x7f050001;
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
|
||||||
*
|
|
||||||
* This class was automatically generated by the
|
|
||||||
* aapt tool from the resource data it found. It
|
|
||||||
* should not be modified by hand.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.facebook.android;
|
|
||||||
|
|
||||||
public final class R {
|
|
||||||
public static final class attr {
|
|
||||||
}
|
|
||||||
public static final class drawable {
|
|
||||||
public static final int facebook_icon=0x7f020000;
|
|
||||||
public static final int icon=0x7f020001;
|
|
||||||
}
|
|
||||||
public static final class id {
|
|
||||||
public static final int authCode=0x7f060002;
|
|
||||||
public static final int authOkButton=0x7f060001;
|
|
||||||
public static final int authWebView=0x7f060003;
|
|
||||||
public static final int widgetbutton=0x7f060000;
|
|
||||||
}
|
|
||||||
public static final class layout {
|
|
||||||
public static final int main=0x7f030000;
|
|
||||||
public static final int travelpostwidget=0x7f030001;
|
|
||||||
public static final int webauth=0x7f030002;
|
|
||||||
}
|
|
||||||
public static final class string {
|
|
||||||
public static final int app_name=0x7f050001;
|
|
||||||
public static final int hello=0x7f050000;
|
|
||||||
}
|
|
||||||
public static final class xml {
|
|
||||||
public static final int settings=0x7f040000;
|
|
||||||
public static final int travelpostwidgetinfo=0x7f040001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
BIN
TravelPost/libs/twitter4j-core-2.1.11.jar
Normal file
BIN
TravelPost/libs/twitter4j-core-2.1.11.jar
Normal file
Binary file not shown.
@@ -6,13 +6,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.TravelPost;
|
package com.TwentyCodes.android.TravelPost;
|
||||||
|
|
||||||
|
import twitter4j.TwitterException;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The broadcast receiver that works with LocationService.java
|
* The broadcast receiver that works with LocationService.java
|
||||||
@@ -44,8 +45,12 @@ public class LocationReceiver extends BroadcastReceiver{
|
|||||||
*/
|
*/
|
||||||
private void onLocationUpdate(Location location) {
|
private void onLocationUpdate(Location location) {
|
||||||
//TODO something with the location i.e. report location to social services like twitter, ect...
|
//TODO something with the location i.e. report location to social services like twitter, ect...
|
||||||
SharedPreferences shared_prefs = mContext.getSharedPreferences(TravelPost.SETTINGS, Context.MODE_PRIVATE);
|
try {
|
||||||
TravelPost.tweet(shared_prefs.getString(TravelPost.TWITTER_AUTH_CODE, ""), "yellow_jk", location.toString());
|
TravelPost.tweet(location.toString());
|
||||||
|
} catch (TwitterException e) {
|
||||||
|
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_LONG);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
removeWakeLock();
|
removeWakeLock();
|
||||||
|
|||||||
@@ -6,8 +6,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.TravelPost;
|
package com.TwentyCodes.android.TravelPost;
|
||||||
|
|
||||||
import winterwell.jtwitter.OAuthSignpostClient;
|
import twitter4j.Twitter;
|
||||||
import winterwell.jtwitter.Twitter;
|
import twitter4j.TwitterException;
|
||||||
|
import twitter4j.TwitterFactory;
|
||||||
|
import twitter4j.conf.ConfigurationBuilder;
|
||||||
|
import twitter4j.http.AccessToken;
|
||||||
|
import twitter4j.http.RequestToken;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@@ -15,6 +19,8 @@ import android.os.Bundle;
|
|||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main activity for the Travel Post widget.
|
* Main activity for the Travel Post widget.
|
||||||
@@ -24,13 +30,15 @@ import android.preference.PreferenceActivity;
|
|||||||
public class TravelPost extends PreferenceActivity implements OnPreferenceClickListener {
|
public class TravelPost extends PreferenceActivity implements OnPreferenceClickListener {
|
||||||
|
|
||||||
private PostMortemReportExceptionHandler mExceptionReport = new PostMortemReportExceptionHandler(this);
|
private PostMortemReportExceptionHandler mExceptionReport = new PostMortemReportExceptionHandler(this);
|
||||||
|
private RequestToken requestToken;
|
||||||
private static SharedPreferences shared_prefs;
|
private static SharedPreferences shared_prefs;
|
||||||
public static final String SETTINGS = "settings";
|
public static final String SETTINGS = "settings";
|
||||||
private static final int TWITTER_AUTH_REQUEST_CODE = 0;
|
private static final int TWITTER_AUTH_REQUEST_CODE = 0;
|
||||||
public static final String TWITTER_AUTH_CODE = "twitter";
|
public static final String TWITTER_AUTH_TOKEN = "twitter_token";
|
||||||
private static final String TC_TEST_OAUTH_KEY = "SSO8Vpy2Ecmc3BjvtwoRw";
|
public static final String TWITTER_AUTH_SECRET = "twitter_secret";
|
||||||
private static final String TC_TEST_OAUTH_SECRET = "aa6t6N0wlenvbWzU7fZbrhgzmEmUl5s7zGRbbKoU";
|
private static final String TC_TEST_OAUTH_KEY = "kmmcF8rjO4Aj9W4g8ao8ow";
|
||||||
|
private static final String TC_TEST_OAUTH_SECRET = "5pgeFWHd7dkde284ed7NsRuIVsyeOvioXR0tVxp9K8";
|
||||||
|
private static final String TAG = "TravelPost";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* called when the activity is first created
|
* called when the activity is first created
|
||||||
@@ -45,9 +53,7 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
|
|||||||
mExceptionReport.run();
|
mExceptionReport.run();
|
||||||
Thread.setDefaultUncaughtExceptionHandler(mExceptionReport);
|
Thread.setDefaultUncaughtExceptionHandler(mExceptionReport);
|
||||||
|
|
||||||
// set shared_prefs name
|
shared_prefs = getSharedPreferences(SETTINGS, 0);
|
||||||
getPreferenceManager().setSharedPreferencesName(SETTINGS);
|
|
||||||
shared_prefs = getPreferenceManager().getSharedPreferences();
|
|
||||||
|
|
||||||
// load preferences xml
|
// load preferences xml
|
||||||
this.addPreferencesFromResource(R.xml.settings);
|
this.addPreferencesFromResource(R.xml.settings);
|
||||||
@@ -56,9 +62,16 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
OAuthSignpostClient client = new OAuthSignpostClient(TC_TEST_OAUTH_KEY, TC_TEST_OAUTH_SECRET, "oob");
|
Twitter twitter = new TwitterFactory().getInstance();
|
||||||
this.startActivityForResult(new Intent(this, WebAuth.class).putExtra(WebAuth.AUTH_URL, client.authorizeUrl().toString()), TWITTER_AUTH_REQUEST_CODE);
|
twitter.setOAuthConsumer(TC_TEST_OAUTH_KEY, TC_TEST_OAUTH_SECRET);
|
||||||
|
try {
|
||||||
|
requestToken = twitter.getOAuthRequestToken();
|
||||||
|
this.startActivityForResult(new Intent(this, WebAuth.class).putExtra(WebAuth.AUTH_URL, requestToken.getAuthorizationURL()), TWITTER_AUTH_REQUEST_CODE);
|
||||||
|
} catch (TwitterException e) {
|
||||||
|
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,29 +83,47 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
Log.v(TAG, "onActivityResult()");
|
||||||
|
Log.d(TAG, "Request code:"+ requestCode);
|
||||||
|
if(data != null)
|
||||||
|
Log.d(TAG, data.getStringExtra(WebAuth.AUTH_CODE));
|
||||||
|
else
|
||||||
|
Log.e(TAG, "WebAuth result was null!!!");
|
||||||
if(resultCode == Activity.RESULT_OK)
|
if(resultCode == Activity.RESULT_OK)
|
||||||
switch(requestCode){
|
switch(requestCode){
|
||||||
case TWITTER_AUTH_REQUEST_CODE:
|
case TWITTER_AUTH_REQUEST_CODE:
|
||||||
shared_prefs.edit().putString(TWITTER_AUTH_CODE, data.getStringExtra(WebAuth.AUTH_CODE)).commit();
|
try {
|
||||||
|
AccessToken accessToken = null;
|
||||||
//FOR TESTING
|
Twitter twitter = new TwitterFactory().getInstance();
|
||||||
// OAuthSignpostClient client = new OAuthSignpostClient(TC_TEST_OAUTH_KEY, TC_TEST_OAUTH_SECRET, "oob");
|
accessToken = twitter.getOAuthAccessToken(requestToken, data.getStringExtra(WebAuth.AUTH_CODE));
|
||||||
// client.setAuthorizationCode(data.getStringExtra(WebAuth.AUTH_CODE));
|
Log.d(TAG, accessToken.getToken());
|
||||||
// Twitter twitter = new Twitter("yellow_jk", client);
|
Log.d(TAG, accessToken.getTokenSecret());
|
||||||
// // Optional: store the authorisation token details
|
shared_prefs.edit().putString(TWITTER_AUTH_TOKEN, accessToken.getToken()).commit();
|
||||||
// Object accessToken = client.getAccessToken();
|
shared_prefs.edit().putString(TWITTER_AUTH_SECRET, accessToken.getTokenSecret()).commit();
|
||||||
//
|
|
||||||
// // use the API!
|
} catch (TwitterException e) {
|
||||||
// twitter.setStatus("test");
|
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tweet(String authCode, String userName, String msg){
|
/**
|
||||||
OAuthSignpostClient client = new OAuthSignpostClient(TC_TEST_OAUTH_KEY, TC_TEST_OAUTH_SECRET, "oob");
|
* posts a tweet to twitter
|
||||||
Twitter jtwit = new Twitter(userName, client);
|
* @param msg
|
||||||
client.setAuthorizationCode(authCode);
|
* @throws TwitterException
|
||||||
jtwit.setStatus(msg);
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static void tweet(String msg) throws TwitterException{
|
||||||
|
ConfigurationBuilder cb = new ConfigurationBuilder();
|
||||||
|
cb.setDebugEnabled(true);
|
||||||
|
cb.setOAuthConsumerKey(TWITTER_AUTH_TOKEN).setOAuthConsumerSecret(TWITTER_AUTH_SECRET);
|
||||||
|
cb.setOAuthAccessToken(shared_prefs.getString(TWITTER_AUTH_TOKEN, ""));
|
||||||
|
cb.setOAuthAccessTokenSecret(shared_prefs.getString(TWITTER_AUTH_SECRET, ""));
|
||||||
|
TwitterFactory tf = new TwitterFactory(cb.build());
|
||||||
|
Twitter twitter = tf.getInstance();
|
||||||
|
twitter.updateStatus(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ public class WebAuth extends Activity implements OnClickListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
this.setResult(RESULT_OK, new Intent().putExtra(AUTH_CODE, mAuthCode.getText().toString()));
|
setResult(RESULT_OK, new Intent().putExtra(AUTH_CODE, mAuthCode.getText().toString()));
|
||||||
this.finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user