- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目标
在我的相机应用中,我想让用户在用户的 Facebook 墙上分享一张带有预格式化文本和描述的图片。
简介
我在谷歌上搜索了很多并关注了“the terrific” facebook-getting-started ,尝试了很多东西,持续了 !!days!!... 还没有找到完全可行的解决方案。
至少我认为我得到了一些分数:
出色的 Android Intent action_send 效果很好但不选择 facebook,它适用于文本或图片,但不适用于两者 (!!),请参阅 here
applicationID、hashxxx 以及将 android 应用程序链接到 facebook 登录所需的所有其他内容,所有我真的不理解和不想理解的东西,完成并最终工作(感谢 facebook 的所有这些 sh *t!!)
可以与 facebook 分享(参见 here ):
3a.使用 facebook 应用程序(安装在设备中)
3b.使用登录 session (如果未安装 Facebook 应用程序)
Facebook 要我们使用它的 SDK,这很 [b|s] 广告,但我可以忍受。
案例 3a - facebook 建议我们使用 shareDialog,并且 - 与建议的代码 fragment 和示例进行了很多斗争! - 我已经能够做到,但如果 facebook 应用程序不是,我也需要它来工作安装(案例 3b。)
案例 3b - facebook 建议使用“丑陋的”feedDialog 作为后备(参见 here)。
6a. feedDialog 需要登录,没关系...
6b. feedDialog好像不能分享本 map 片,我真的不明白为什么... here facebook 指南仅谈论“图片”关键字的“URL”...
5c.然后我想我必须使用 Request,我尝试实现它但没有任何反应,我想我遗漏了一些东西...没有找到有用的引用(=工作示例)。
代码 fragment 从 SO 和 developers.facebook 复制/粘贴/编辑
ShareDialog 和 session 管理,以防未安装 Facebook 应用正常运行
/**
* share image with facebook, using facebook sdk
* @param pathToImage
*/
private void shareWithFacebook(String pathToImage) {
Log.i("SHARE", "share with facebook");
if (FacebookDialog.canPresentShareDialog(getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
// Publish the post using the Share Dialog
Log.i("SHARE", "share with ShareDialog");
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
.setCaption("Sharing photo taken with MyApp.")
.setName("Snail Camera Photo")
.setPicture("file://"+pathToImage)
.setLink("http://myapplink")
.setDescription("Image taken with MyApp for Android")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
// maybe no facebook app installed, trying an alternative
// here i think i need a session
if (Session.getActiveSession() != null && Session.getActiveSession().isOpened()) {
publishFeedDialog(pathToImage);
} else {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
List<String> permissions = new ArrayList<String>();
permissions.add("publish_actions");
session.openForRead(new Session.OpenRequest(this)
.setPermissions(permissions)
.setCallback(mFacebookCallback));
} else {
Session.openActiveSession(this, true, mFacebookCallback);
}
}
}
}
private Session.StatusCallback mFacebookCallback = new Session.StatusCallback() {
public void call(final Session session, final SessionState state, final Exception exception) {
if (state.isOpened()) {
String facebookToken = session.getAccessToken();
Log.i("SHARE", facebookToken);
Request.newMeRequest(session, new Request.GraphUserCallback() {
public void onCompleted(GraphUser user, com.facebook.Response response) {
publishFeedDialog(MP.LAST_TAKEN_FOR_GALLERY);
}
}).executeAsync();
}
}
};
feedDialog fragment ,适用于文本字段、链接和远程 url,但不适用于使用“file://...”或“file:///...”的本 map 片 .错误消息:图片 URL 的格式不正确
。
private void publishFeedDialog(String pathToImage) {
Bundle params = new Bundle();
params.putString("name", "myapp Photo");
params.putString("caption", "Sharing photo taken with myapp.");
params.putString("description", "Image taken with myapp for Android");
params.putString("link", "http://myapp.at.playstore");
params.putString("picture", "file://"+pathToImage);
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(EnhancedCameraPreviewActivity.this,//getApplicationContext(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
public void onComplete(Bundle values,
FacebookException error) {
Log.i("SHARE", "feedDialog.onComplete");
if (error == null) {
// story is posted
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(),
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
另一个尝试,使用 Request,它说:
photo upload problem. Error={HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) Requires extended permission: publish_actions}
我尝试在上面的 session 管理中添加 publish_actions 权限,也许我错过了什么......
private void publishFeedDialog(String pathToImage) {
Request request=Request.newPostOpenGraphObjectRequest(
Session.getActiveSession(),
"PhotoUpload",
"myApp Photo Upload",
"file://"+pathToImage,
"http://myapp.at.playstore",
"Image taken with myApp for Android",
null,
uploadPhotoRequestCallback);
request.executeAsync();
}
最后尝试使用 Request,无论是否使用“picture”关键字,都没有任何反应。
private void publishFeedDialog(String pathToImage) {
Bundle parameters = new Bundle();
parameters.putString("message", "Image taken with myApp for Android");
parameters.putString("picture", "file://"+pathToImage);
parameters.putString("caption", "myApp Photo");
Request request = new Request(Session.getActiveSession(), "/me/feed", parameters, null);
// also tried: Request request = new Request(Session.getActiveSession(), "/me/feed", parameters, com.facebook.HttpMethod.POST);
request.executeAsync();
}
问题
-1- 我的 1..6 点是否有错误?
-2- 我可以使用 FeedDialog 分享本 map 片吗?
-3-如果没有,没有安装facebook app怎么办?
非常感谢!
最佳答案
我有同样的问题,但我有解决方法。
这会将图片上传到用户个人资料并将其张贴在他\她的墙上,之后您可以根据需要获取 URL:
private void uploadPicture(final String message, Session session) {
Request.Callback uploadPhotoRequestCallback = new Request.Callback() {
@Override
public void onCompleted(com.facebook.Response response) {
if (response.getError() != null) {
Toast.makeText(getActivity(), "Failed posting on the Wall", Toast.LENGTH_LONG).show();
return;
}
Object graphResponse = response.getGraphObject().getProperty("id");
if (graphResponse == null || !(graphResponse instanceof String) ||
TextUtils.isEmpty((String) graphResponse)) {
Toast.makeText(getActivity(), "Failed uploading the photo\no respons", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity(), "Succsefully posted on the facebook Wall", Toast.LENGTH_LONG).show();
}
}
};
// Execute the request with the image and appropriate message
Request request = Request.newUploadPhotoRequest(session, profileBitmap, uploadPhotoRequestCallback);
Bundle params = request.getParameters();
params.putString("message", message);
request.executeAsync();
}
在没有APP的情况下启动facebook登录,更简单,我使用以下代码 fragment 在facebook按钮上调用facebook SDK:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.faceBookButton:
if (((imagePath != null && !imagePath.equals("")) || (message != null && !message.equals("")))) {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForPublish(new Session.OpenRequest(this)
.setPermissions(Arrays.asList("public_profile", "publish_actions"))
.setCallback(statusCallback));
} else {
if (profileBitmap != null) {
uploadPicture(message, session);
} else {
publishFeedDialog(message);
}
}
} else {
Toast.makeText(getActivity(), getString(R.string.checkin_fail), Toast.LENGTH_SHORT).show();
}
break;
}
}
在我的例子中,publishFeedDialog 接受您要传递的消息,而不是图像,但这并不重要。无论如何,它都会打开 Facebook 的消息对话框,我还没有找到从我的 EditText 小部件传递预定义消息的方法。
关于android - Facebook SDK : share local picture with text is driving me crazy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25095996/
我正在对 Share 开发和执行一些自定义。我的 IDE 是 Eclipse Juno,工作区由以下元素组成: 露天网络项目 扩展 Java 项目 分享网站项目 alfresco 和 share we
这是我一直面临的一个非常奇怪的问题。我正在使用 Share.share,它将消息、主题 (ios) 和标题(对于 gmail)作为参数。在android中它工作正常。即主题行是“我是标题”,而消息正文
当在static上下文中未使用而不是时(也就是说,当static关键字不存在并且您不在全局范围内时),shared和__gshared关键字有什么作用? 例子: struct Temp {
我想知道如何从 Surf 中的 Root 对象知道当前主机名。 我正在编写一个服务于 JNLP 的网络脚本,所以我没有页面上下文,并且 ${url.context} 只返回 /share。 我正在寻找
我想知道如何从 Surf 中的 Root 对象知道当前主机名。 我正在编写一个服务于 JNLP 的网络脚本,所以我没有页面上下文,并且 ${url.context} 只返回 /share。 我正在寻找
我需要在 Alfresco Share 上下文中创建一个无需身份验证即可访问的页面。使用页面框架时,它看起来非常简单,因为您可以添加 none到页面定义。 当使用 aikau 时,页面定义消失了,我只
我有执行REST命令并处理结果的python脚本。我希望该脚本可被不同的Jenkins Pipelines使用,我通过Jenkins官方文档发现的一种方式是使用“共享库”,而这些示例(以及我在网上找到
查看此函数(矩阵 vector 积): std::vector times(std::vector > const& A, std::vector const& b, int m, int n) {
我正在尝试弄清楚如何与 Alfresco Share 执行一些 dashlet 间通信。 这是一个简单的用例: 我们确实有 2 个 dashlet,我们称它们为 A 和 B。我希望能够在 A 中填写字
是否可以在 Snowflake 的 FUNCTION 或 PROCEDURE 中发出“Show Shares”函数调用?由于信息架构中没有元数据对象来查询有关共享的信息,因此我们正在寻找一种方法来创建
我对“无共享”分布式系统的理解是集群中的每个节点都有自己的磁盘可以持久化。如果是这种情况,我不确定为什么拥有这样的架构会有好处,因为您不仅需要在应用程序级别进行复制/负载平衡/集群,而且还需要在磁盘上
我对“无共享”分布式系统的理解是集群中的每个节点都有自己的磁盘可以持久化。如果是这种情况,我不确定为什么拥有这样的架构会有好处,因为您不仅需要在应用程序级别进行复制/负载平衡/集群,而且还需要在磁盘上
在 Alfresco 4.0 中,我想扩展 Share Doclib Filter webscript 以添加我自己的自定义过滤器。 有没有一种简单的方法可以在 share-config-custom
假设我要匹配: PREFIXsomething 或: somethingPOSTFIX 但肯定不是: PREFIXsomethingPOSTFIX 其中 something 是某种共享模式,而 PRE
我正在寻找一种使用 JavaScript 在 google drive sdk 上查找用户共享文件列表的方法。 重要提示:我不是在寻找“与我共享”的文件列表。 我目前所拥有的列出了“与我共享”的文件,
最近刚开始使用 swifting,在使用应用程序组在 iOS 设备之间共享数据时遇到了问题。 基本上我已经按照以下步骤设置了项目: [iPhone] 为 iPhone 目标启用应用程序组 初始化数据如
我知道 -Wl,-shared 是 ld 的一个选项。我见过有人这样编译, $ gcc -shared -Wl,-soname,libtest.so -o libtest.so *.o 还有这样的人
我想知道对这句名言最接地气的解释是什么: Don't communicate by sharing memory; share memory by communicating. (R. Pike) 在
我不确定我在这里做错了什么,我认为应该有更多的文档或关于这个Web Share API的更好的错误描述。。我正在尝试共享以下文件。使用。我已经确保该类型是允许的类型,但我一直收到DOMExceptio
我正在研究 RxSwift 和 RxCocoa。官方文档中有这些解释。 分享副作用 分享资源 它们是一样的吗?如果有区别,那有什么区别?光看官方文档的解释,我看不懂。 预先感谢您的回答。 最佳答案 文
我是一名优秀的程序员,十分优秀!