- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在我的 Android 应用程序中使用 Facebook,它工作得很好。
但是,我意识到每次登录时都会出现无用的屏幕,说“您已经授权使用此应用程序”并带有确定和取消选项。
如何避免或从我的应用程序中删除此屏幕。
我在 Google 上搜索并找到了一些针对旧版 Facebook SDK 的答案,但是如何使用新版 Facebook SDK(3.0 及更高版本)实现它呢?
这是我的代码,
public void onClick(View v)
{
Bundle myParams = new Bundle();
myParams.putString("message", " DOWNLOAD THE 'Saragama' ANDROID APP FROM " + url_android.toString()
+ ". Fully integrated with Facebook and Twitter.");
myParams.putString("name", mSharingText.getText().toString());
myParams.putString("caption", "www.saragama.com");
myParams.putString("description", "Various religios music, chants, mantras, christian songs, islamic music, quran and more on saragama");
myParams.putString("link", "http://android.saragama.com");
myParams.putString("picture", albumImageURL);
if (PlusUtilities.isInternetConnected())
{
// ~post your data
Session session = Session.getActiveSession();
if (session != null)
{
MyLog.w("session state", session.getState().toString());
if (session.getState().equals(SessionState.OPENED) || session.getState().equals(SessionState.OPENED_TOKEN_UPDATED))
{
publishStory(myParams);
}
else
{
plusUtilities1.showAlertDialog("Please login first!");
}
}
else
{
plusUtilities1.showAlertDialog("Please login first!");
}
}
else
{
plusUtilities1.showAlertDialog("Problem occured with your internet connection!");
}
}
// Facebook Login-------------------------------------------------------------------------------------
private void loginToFacebook()
{
if (PlusUtilities.isInternetConnected())
{
Session session = Session.getActiveSession();
// if session is in exceptional state
if (session.getState() == SessionState.CLOSED_LOGIN_FAILED || session.getState() == SessionState.OPENING)
{
session.closeAndClearTokenInformation();
}
if (!session.isOpened() && !session.isClosed())
{
String[] PERMISSION_ARRAY_PUBLISH =
{"publish_actions" };
List<String> PERMISSION_LIST = Arrays.asList(PERMISSION_ARRAY_PUBLISH);
session.openForPublish(new Session.OpenRequest(FacebookActivity.this).setPermissions(PERMISSION_LIST).setCallback(
statusCallback1));
}
else
{
Session.openActiveSession(this, true, statusCallback1);
}
}
else
{
plusUtilities1.showAlertDialog("Please check your internet connection!");
}
}
@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent data)
{
super.onActivityResult(requestCode, responseCode, data);
// plusUtilities1.ShowToast("onActivityResult");
MyLog.i("onActivityResult requestCode :responsecode:session state", requestCode + ":" + responseCode + ":"
+ Session.getActiveSession().getState().toString());
switch (requestCode)
{
case MyRaagaLoginActivity.REQUEST_CODE_FACEBOOK_LOGIN:
if (responseCode == RESULT_OK)
{
MyLog.e("Login", "trying to facebook Login");
Session.getActiveSession().onActivityResult(Act1, requestCode, responseCode, data);
}
else
{
plusUtilities1.ShowToast("User access denied!");
}
break;
default:
MyLog.i("case:", "default");
break;
}
}
/**
* function to get active facebook session if already exist or create the new session
*
* @param savedInstanceState
* =check if Session exist and restored in bundle during onSaveInstanceState() system call
* @author DeepakD
*/
public void GetOrCreateFacebookActiveSession(Bundle savedInstanceState)
{
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Settings.addLoggingBehavior(LoggingBehavior.REQUESTS);
Session session = Session.getActiveSession();
// if session is null try to find if session is saved previously
if (session == null)
{
if (savedInstanceState != null)
{
session = Session.restoreSession(this, null, statusCallback1, savedInstanceState);
}
// if still session is null then create the new session
if (session == null)
{
session = new Session(this);
}
// set the created session as active session
Session.setActiveSession(session);
}
updateFBbutton();
}
/**
* set login or logout button
*/
private void updateFBbutton()
{
Session session = Session.getActiveSession();
if (session.isOpened())
{
FbLoginbtn.setText("FBLogout");
FbLoginbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{
onClickFBLogout();
}
});
}
else
{
FbLoginbtn.setText("FBLogin");
FbLoginbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{
loginToFacebook();
}
});
}
}
/**
* Logout from facebook
*/
private void onClickFBLogout()
{
Session session = Session.getActiveSession();
if (!session.isClosed())
{
session.closeAndClearTokenInformation();
plusUtilities1.ShowToast("Logout successful");
}
}
/**
* This class is used to fetch the current status of active session
*
* @author DeepakD
*
*/
private class SessionStatusCallback1 implements Session.StatusCallback
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
updateFBbutton();
plusUtilities1.DissmissPD();
MyLog.w("session state", session.getState().toString());
if(session.getState()==SessionState.CLOSED_LOGIN_FAILED)
{
//login failed
plusUtilities1.ShowToast("Unable to connect,please try later..");
session.closeAndClearTokenInformation();
}
if (session.getState()== SessionState.OPENED)
{
//login successful
plusUtilities1.ShowToast("Login successful");
}
}
}
/**
* actually post the data on facebook
*
* @param myParams
* Bundle of parameters to be post
*/
private void publishStory(Bundle myParams)
{
plusUtilities1.ShowPD("Sharing data...");
Session session = Session.getActiveSession();
if (session != null)
{
// Check for publish permissions
List<String> permissions = session.getPermissions();
try
{
if (!isSubsetOf(PERMISSIONS, permissions))
{
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
}
}
catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
Request.Callback callback = new Request.Callback()
{
public void onCompleted(Response response)
{
plusUtilities1.DissmissPD();
MyLog.w("post response", "" + response.toString());
if (response.getError() == null)
{
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
String postId = null;
try
{
postId = graphResponse.getString("id");
}
catch (JSONException e)
{
Toast.makeText(FacebookActivity.this, "JSON error " + e.getMessage(), Toast.LENGTH_LONG)
.show();
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(FacebookActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
FacebookRequestError error = response.getError();
Log.e("post response", response.toString());
if (error != null)
{
Toast.makeText(FacebookActivity.this, error.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(FacebookActivity.this, "Posted successfully!",
Toast.LENGTH_LONG).show();
FlurryAgent.logEvent("Audio Facebook share -" + EventName);
}
}
else
{
plusUtilities1.showAlertDialog("Something went wrong while posting!");
}
}
};
MyLog.w("BUNDLE TO BE POSTED;", myParams.toString());
Request request = new Request(session, "/me/feed", myParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
public static boolean isSubsetOf(Collection<String> subset, Collection<String> superset)
{
for (String string : subset)
{
if (!superset.contains(string))
{
return false;
}
}
return true;
}
protected void onStart()
{
super.onStart();
MyLog.i("FacebookActivity", "onStart");
FlurryAgent.onStartSession(this, KeysCls.Flurry_Analytics_Key);
FlurryAds.displayAd(this, "AppCircle_Ads", linlayAdLayout);
if (PlusUtilities.isInternetConnected())
{
Session.getActiveSession().addCallback(statusCallback1);
}
else
{
plusUtilities1.showAlertDialog("Please check your internet connection and try again!");
}
}
/**
* convert post's simple text to text with links
*
* @param Name
* @param Link
* @return
*/
String wallpostWithLink(String Name, String Link)
{
jo = new JSONObject();
try
{
jo.put("name", Name);
jo.put("link", Link);
}
catch (Exception e)
{
e.printStackTrace();
}
return jo.toString();
}
@Override
protected void onStop()
{
super.onStop();
FlurryAgent.onEndSession(this);
}
最佳答案
转到 developers.facebook.com并在 Settings-> Basic->Single Sign On -> YES
关于android - Facebook SDK 3.0 :How to remove "you have already authorized to this app" screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17615819/
我在 * nix 中相当新。有没有办法创建一个屏幕,它会立即执行给定的命令序列(带有自己的参数)?两个小时的谷歌搜索一无所获——也许是因为我不能 清楚地陈述问题。 我希望像 screen -dmS n
我顺风顺风margin配置文件中的属性: module.exports = { theme: { extend: { 'margin': {
我正在 cygwin 环境中配置 GNU 屏幕。实际上重新配置——它之前总是有效,当我升级到 cygwin-64 时,相同的配置文件给了我意想不到的行为。 发生的情况是,每当我在终端中执行溢出全屏的操
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 10年前关闭。 Improve this
我想使用 GNU screen 来监视这样的串行 USB 端口: $ screen /dev/ttyUSB0 115200 但我需要调整一些终端线路设置。我已经进行了几次尝试,但似乎都没有奏效。例如,
我需要在我的 .screenrc 中放入什么才能创建嵌套 session (即:屏幕中的屏幕)? 目前,如果我运行 screen再次从打开的屏幕选项卡中,而不是在该选项卡中打开一个新的屏幕 sessi
我通常像这样使用 gnu 屏幕: 1. 为我的所有任务启动一个屏幕 session 2.当我登录到一台机器时,我连接到我同事制作的屏幕 session (screen -x)(因此这使它成为“内部屏幕
使用屏幕,我知道我可以按名称命名和重新附加到 session : screen -S screen -r 当我执行 screen -ls我得到一个 session 列表,但
如何增加screen中可以查看的行数? 我想查看从运行screen -S 到当前操作的那几行。例如,如何将缓冲区长度增加到大约50000行? 我已经尝试过^a :scrollback ,但是它不会增加
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 8年前关闭
作为设置桌面的启动脚本的一部分,我初始化了一个带有多个窗口的 screen 。为此,我启动一个守护进程并向其发送 -X screen 和 -X stuff 命令,最后使用 -r 重新连接。 不幸的是,
当我开始时 screen ,我收到以下消息: Screen version 4.00.03jw4 (FAU) 2-May-06 Copyright (c) 1993-2002 Juergen Weig
刚刚开始使用 Screen 与 Vim 进行远程配对编程。 想知道是否有办法调整窗口大小,因为我们的终端空间在默认设置下非常有限。 目前我正在进入这样的屏幕: User 1: screen -R te
所以我一直在尝试寻找一些关于 GNU screen 实际上如何在 high 下工作的信息,而不必真正阅读源代码,但我一直无法这样做。 screen 做了什么,即使在终端 session 关闭时它也能保
我有一个游戏服务器。它通过 dotnet 在 linux 上运行。我在“screen ” session 中运行它。但是我正在努力重新启动此服务器。从外面看,很容易。我只是通过名称杀死现有 scree
我想使用 mac/linux 命令 screen 启动多个 screen ,让每个 screen 执行我的 .bashrc,然后从该 .bashrc 运行一系列别名/函数。我尝试在我的 .screen
当我在终端工作时,我会看到最后一个 shell 命令执行输出的历史记录。如果我运行 vim,我会看到我全屏打开的文件。当我退出 vim 时,我可以再次看到最后一个 shell 命令的历史。 但是,当我
我正在写一个小脚本,它确实向正在运行的屏幕 session 发送命令。此命令会停止屏幕,但不会立即停止。我需要等待它完成才能继续执行脚本的其余部分。 这就是我停止屏幕的方式: screen -S $S
我们在办公室经常使用 gnu screen ,有时如果我不注意,我最终会迷失在我已经在哪个 screen session 中。 所以我的问题是,你怎么知道你在哪个屏幕 session 中?你有办法查吗
我想知道 Mozenda Screen Scraper 是如何编码的? http://www.mozenda.com/screen-scraper 我展示了一个浏览器,用户可以在其中选择他想要删除的字
我是一名优秀的程序员,十分优秀!