分享媒体内容使用facebook sdk 4.x +

时间:2015-07-13 04:59:09

标签: android facebook facebook-graph-api

我举例说明在Android中使用facebook sdk将我的状态(包括链接,照片,视频)发布到我的墙上。 请关注此Facebook的教程链接:facebook startup tutorial我已登录并通过ShareLinkContent类成功发布链接状态。但是,如果没有安装官方的android facebook app,我就无法分享照片(SharePhotoContent类)和视频(ShareVideoContent类)。教程不要求首先安装他们的应用程序,但我不能使用我的示例应用程序发布我的照片,视频没有安装他们的应用程序。

radius <- .1 # of a ball containing the largest label

d <- as.matrix(dist(data[, c("x","y")], upper=TRUE, diag=TRUE))
remaining <- 1:N
spaced <- numeric()
i <- 1
while(length(remaining)>0) {
  p <- ifelse(length(remaining)>1, sample(remaining, 1), remaining)  
  spaced <- c(spaced, p)  # ...   
  remaining <- setdiff(remaining, which(d[p, ] < 2*radius))
  i <- i + 1
}

frame()
plot(x,y)
spaced_labels <- data[spaced, ]
with(spaced_labels, text(x,y,labels))
无论他们安装了facebook app,

始终都会返回

import networkx as nx
import matplotlib.pyplot as plt
import random

G=nx.Graph(name="buba")
routes = [[2, 1, 4, 3, 11], [1, 0, 3, 11, 10], [10, 11, 3, 4, 1]]
edges = [ (2,1), (1,4), (4,3), (3,11), (1,0), (0,3), (11,10)]
for r in routes:
     G.add_nodes_from(r)
G.add_edges_from(edges)

print("Graph has %d nodes with %d edges" %(G.number_of_nodes(),    
G.number_of_edges()))
nx.draw_networkx(G,with_labels=True)
plt.savefig('this.png')
plt.show()

如果安装了他们的Facebook app,则只返回true

我分享照片的代码:

ShareDialog.canShow(ShareLinkContent.class)

分享视频的代码:

ShareDialog.canShow(SharePhotoContent.class)
ShareDialog.canShow(ShareVideoContent.class)

我已经设置了我应用的权限:&#34; publish_actions&#34;。

我错过了什么吗?或者Trully我必须首先安装Facebook应用程序才能使用他们提供的sdk开发我的应用程序(包括发布照片,视频)?

1 个答案:

答案 0 :(得分:0)

你有没有初始化Facebook SDK ........ 如果是,那么请问这样的许可

Set<String> permissions = AccessToken.getCurrentAccessToken()
        .getPermissions();

final List<String> PUBLISH_PERMISSIONS = Arrays
        .asList("publish_actions");
if (!permissions.containsAll(PUBLISH_PERMISSIONS)) {

    // pendingPublishReauthorization = true;
    LoginManager.getInstance().logInWithPublishPermissions(this,
            PUBLISH_PERMISSIONS);
    return;
}

然后检查您是否能够发布网络图像......就像这样

 ShareLinkContent content1 = new ShareLinkContent.Builder()
            .setContentUrl(
                    Uri.parse("https://play.google.com/store/apps/details?id=pk.wisesolutions.naatcollection"))
            .setContentTitle(final_messgae)
            .setContentDescription(
                    "Naat Collection App - listen to hundreds of naats free")
            .setImageUrl(
                    Uri.parse("http://apps.wisesolutions.pk/app/naatcollection/images/logo_180x180.png"))
            .build();

    MessageDialog.show(mContext, content1);
相关问题