我有一个奇怪situation.I我试图用我的app.But整合Facebook的登录名和岗位墙壁仅适用于第一再寄一次我打过去2天,无法找到一个解决方案。
下面是code片断:
// ............. Facebook的...................... ....
私有静态最后弦乐APP_ID =我的应用程序ID;
// Facebook的类的实例
私人商标=新的Facebook(APP_ID);
私人AsyncFacebookRunner mAsyncRunner;
私人共享preferences米preFS;
字符串access_token;
长届满;
//............Facebook..............................//
否则,如果(actionId == ID_FACEBOOK)
{
mAsyncRunner =新AsyncFacebookRunner(脸谱);
文件名= myList.get(posglobal)获得(文件夹名);
米preFS = GET preferences(MODE_PRIVATE);
access_token = M prefs.getString(access_token,NULL);
到期= M prefs.getLong(access_expires,0);
若(access_token!= NULL){
facebook.setAccessToken(access_token);
Log.d(FB会话,+ facebook.isSessionValid());
}
如果(到期!= 0){
facebook.setAccessExpires(到期);
}
如果(!facebook.isSessionValid()){
facebook.authorize(BoonDriveActivity.this,
新的String [] {电子邮件,publish_stream},
新DialogListener(){
@覆盖
公共无效OnCancel的(){
//函数处理取消事件
}
@覆盖
公共无效的onComplete(束值){
//函数来处理完成事件
//编辑preferences和更新Facebook的acess_token
最终的共享preferences.Editor编辑= M prefs.edit();
editor.putString(access_token
facebook.getAccessToken());
editor.putLong(access_expires
facebook.getAccessExpires());
editor.commit();
LayoutInflater充气= BoonDriveActivity.this.getLayoutInflater();
查看布局= inflater.inflate(R.layout.createsharedialoglinkedin,NULL);
最后AlertDialog D1 =新AlertDialog.Builder(BoonDriveActivity.this)
//此处是您的其他选项...
.setView(布局)
。创建();
。d1.getWindow()setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
d1.show();
lntxtfilename =(TextView中)layout.findViewById(R.id.txtfilename);
lnetmessage =(EditText上)layout.findViewById(R.id.et_message);
ln_btn_share =(按钮)layout.findViewById(R.id.btn_share);
ln_btn_showlink =(按钮)layout.findViewById(R.id.btn_showlink);
lnshowlink =(EditText上)layout.findViewById(R.id.et_showlink);
lntxtfilename.setText(股份++文件名+有:+);
ln_btn_share.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
postToWall();
}
});
}
@覆盖
公共无效onerror的(DialogError错误){
//函数来处理错误
}
@覆盖
公共无效onFacebookError(FacebookError fberror){
//函数来处理Facebook的错误
}
});
}
}
我是一个充气自定义视图上发布的wall.For第一次的值 access_token为null 和到期为零。但是,当我尝试共享对于happens.I调试我的应用程序,发现第二次没有现在有在access_token一定的价值,以及到期和条件的如果(!facebook.isSessionValid())不firing.Any帮助??我知道我使用一些去precated方法,但我找不到更新的教程或单证。
下面是后到隔壁的code:
/ **
*功能,以发布到Facebook墙
* * /
@燮pressWarnings(德precation)
公共无效postToWall(){
//后用户的墙上。
facebook.dialog(这一点,饲料,新DialogListener(){
@覆盖
公共无效onFacebookError(FacebookError E){
}
@覆盖
公共无效onerror的(DialogError E){
}
@覆盖
公共无效的onComplete(束值){
}
@覆盖
公共无效OnCancel的(){
}
});
}
更新:
我用这code生成散列:
//添加code打印出来的密钥散列
尝试 {
PackageInfo信息= getPackageManager()。getPackageInfo(
com.india.webguru.bizboon
PackageManager.GET_SIGNATURES);
对于(签名签名:info.signatures){
消息摘要MD = MessageDigest.getInstance(SHA);
md.update(signature.toByteArray());
Log.d(KeyHash:Base64.en codeToString(md.digest(),Base64.DEFAULT));
的System.out.println(脸谱哈希===>+ Base64.en codeToString(md.digest(),Base64.DEFAULT));
}
}赶上(的NameNotFoundException E){
e.printStackTrace();
}赶上(抛出:NoSuchAlgorithmException E){
e.printStackTrace();
}
解决方案
同样的问题,解决了以下步骤:
方法1
转到CMD:然后 C:\ Program Files文件(x86)的\的Java \ jdk1.7.0_02 \斌
(用你的路径)
1)生成调试键
密钥工具-exportcert -alias androiddebugkey -keystore〜/ .android / debug.keystore | OpenSSL的SHA1 -binary | OpenSSL的BASE64
3 *** W / **************** =(需要调试键)
2)生成散列键
密钥工具-exportcert -alias 3 *** W / **************** = -keystoreC:\ Users \用户的智能手机开发者\ .android \ debug.keystore| OpenSSL的SHA1 -binary | OpenSSL的BASE64
******* + ************ =(要求哈希键)
注:如果散列键提示错误,然后复制粘贴通过Facebook的异常和放大器产生相同的哈希;在结尾处添加=
..
VALID哈希 FACEBOOK
= *************** / A * 0 =
编辑:下载Openssl的&放大器;把像C的文件夹:\ OpenSSL的
更新1 (步骤老虎钳):将Openssl的文件夹在C盘,打开CMD与放后;写命令:
方法2
第1步
C:\ Program Files文件\的Java \ jre7>仓
第2步
C:\ Program Files文件\的Java \ jre7 \ BIN>密钥工具-exportcert -alias androiddebugkey -keyst
矿C:\ Users \用户的智能手机开发\ .android \ debug.keystore| C:\ OpenSSL的\ BIN \ OpenSSL的沙
1 - 二进制| C:\ OpenSSL的\ BIN \ OpenSSL的的base64
输入密钥库密码:机器人
ü*** ZT ***牛逼***2吨***卜* FJ *** W =
第3步
C:\ Program Files文件\的Java \ jre7 \ BIN>密钥工具-exportcert -aliasü*** ZT ***牛逼***2吨***卜* FJ ** * W =
-keystoreC:\ Users \用户的智能手机开发\ .android \ debug.keystore| C:\ OpenSSL的\ BIN
\ OpenSSL的SHA1 -binary |C:\ OpenSSL的\ BIN \ OpenSSL的的base64
输入密钥库密码:机器人
D * W +我*** 9 / 6VS *** NP *** CF *** G =(必需的Hash)
如果你下载了正确的OpenSSL,那么它必须工作,它是一个测试程序。
I have a strange situation.I am trying to integrate facebook with my app.But the login and post to wall works only for the first time.I am struck for the past 2 days and could not find a solution.
Here is the code snippet:
//.............Facebook..........................
private static final String APP_ID = "My app id";
// Instance of Facebook Class
private Facebook facebook = new Facebook(APP_ID);
private AsyncFacebookRunner mAsyncRunner;
private SharedPreferences mPrefs;
String access_token;
long expires;
//............Facebook..............................//
else if(actionId == ID_FACEBOOK)
{
mAsyncRunner = new AsyncFacebookRunner(facebook);
filename=myList.get(posglobal).get("foldername");
mPrefs = getPreferences(MODE_PRIVATE);
access_token = mPrefs.getString("access_token", null);
expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
Log.d("FB Sessions", "" + facebook.isSessionValid());
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(BoonDriveActivity.this,
new String[] { "email", "publish_stream" },
new DialogListener() {
@Override
public void onCancel() {
// Function to handle cancel event
}
@Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
final SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
LayoutInflater inflater=BoonDriveActivity.this.getLayoutInflater();
View layout=inflater.inflate(R.layout.createsharedialoglinkedin,null);
final AlertDialog d1 = new AlertDialog.Builder(BoonDriveActivity.this)
// Your other options here ...
.setView(layout)
.create();
d1.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
d1.show();
lntxtfilename=(TextView)layout.findViewById(R.id.txtfilename);
lnetmessage=(EditText)layout.findViewById(R.id.et_message);
ln_btn_share=(Button)layout.findViewById(R.id.btn_share);
ln_btn_showlink=(Button)layout.findViewById(R.id.btn_showlink);
lnshowlink=(EditText)layout.findViewById(R.id.et_showlink);
lntxtfilename.setText("Share"+" "+filename+" "+"with:");
ln_btn_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
postToWall();
}
});
}
@Override
public void onError(DialogError error) {
// Function to handle error
}
@Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
}
});
}
}
I am inflating a customize view to post on the wall.For the first time the value of access_token is null and expires is zero.But when i try to share for the second time nothing happens.I debugged my application and find that now there is some value in access_token as well as expires and the condition if (!facebook.isSessionValid()) is not firing.Any help??I know I am using some deprecated method but I couldn't find updated tutorials or documentations.
Here is a code of post to wall:
/**
* Function to post to facebook wall
* */
@SuppressWarnings("deprecation")
public void postToWall() {
// post on user's wall.
facebook.dialog(this, "feed", new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
}
@Override
public void onError(DialogError e) {
}
@Override
public void onComplete(Bundle values) {
}
@Override
public void onCancel() {
}
});
}
Update:
I am using this code to generate hash:
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.india.webguru.bizboon",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
System.out.println("Facebook hash===>"+Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
解决方案
Same issue was solved by following steps:
METHOD 1
Goto Cmd : then C:\Program Files (x86)\Java\jdk1.7.0_02\bin
(use your path)
1) Generate Debug key
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
3***W/****************= (require debug key)
2) Generate Hash Key
keytool -exportcert -alias 3***W/****************= -keystore "C:\Users\Smartphone Developer\.android\debug.keystore" | openssl sha1 -binary | openssl base64
*******+************= (require hash key)
Note: if hash key gives error, then copy paste the same hash generated by FaceBook in exception & add "=" in the end
..
VALID HASH FOR FACEBOOK
= ***************/a*0=
Edit: Download Openssl & place the folder like C:\OpenSSL
UPDATE 1 (step vise): After placing Openssl folder in C drive, open cmd & write commands:
METHOD 2
step 1
C:\Program Files\Java\jre7>bin
step 2
C:\Program Files\Java\jre7\bin>keytool -exportcert -alias androiddebugkey -keyst
ore "C:\Users\Smartphone Developer\.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha
1 -binary | "C:\OpenSSL\bin\openssl" base64
Enter keystore password: android
u***ZT***T***2t***bU*Fj***w=
step 3
C:\Program Files\Java\jre7\bin>keytool -exportcert -alias u***ZT***T***2t***bU*Fj***w=
-keystore "C:\Users\Smartphone Developer\.android\debug.keystore" | "C:\OpenSSL\bin
\openssl" sha1 -binary | "C:\OpenSSL\bin\openssl" base64
Enter keystore password: android
d*W+i***9/6vs***nP***CF***g= (Required Hash)
if you downloaded the correct openssl then it must work, its a tested procedure..
上一篇:Android的文件上传 - $ _FILES返回空文件上传、Android、_FILES
下一篇:如何从classpath中加载图像为Android ImageView的?图像、加载、classpath、Android