我正在尝试将图片发布到 ID = 226338660793052 的 Facebook 页面,但它总是以/me/photos 结尾。我做错了什么?
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
imageToSend, @"source",
facebookMessageTextView.text, @"message",
nil];
[facebook requestWithGraphPath:@"/226338660793052/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];
我没有收到错误消息。我什么也没得到,除了照片最终出现在我自己的相册 me/photos 中,而不是在 226338660793052/photos 的相册中。
但是当我只是向该页面发布消息时,我确实在页面的时间轴上获得了成功的帖子:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"http://www.bitsonthego.com", @"link",
@"my profile", @"name",
facebookMessageTextView.text, @"message",
nil];
[facebook requestWithGraphPath:@"/226338660793052/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
我在这里错过了什么?我知道这一定是可能的,因为我可以使用浏览器将图片上传到所需的页面,作为一个随机的非管理员用户。我似乎无法通过图形 API 执行此操作。
更新:
我已经解决了部分问题。您必须使用目标页面的 access_token。这是你如何得到它:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"access_token", @"fields",
nil];
FBRequest *request = [facebook requestWithGraphPath:@"226338660793052" andParams:params andDelegate:self];
当你得到结果时,然后将它添加到上面的事务中:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, @"source",
[result objectForKey:@"access_token"], @"access_token",
facebookMessageTextView.text, @"message",
nil];
FBRequest *request = [facebook requestWithGraphPath:[[result objectForKey:@"id"] stringByAppendingString:@"/photos"] andParams:params andHttpMethod:@"POST" andDelegate:self];
但是,这行不通,因为 Facebook.m 会将这个新的 access_token 替换为默认用户 access_token,因此我在第 166 行左右对 Facebook.m 进行了更改,来自:
if ([self isSessionValid]) {
[params setValue:self.accessToken forKey:@"access_token"];
}
到:
if ([self isSessionValid]) {
if ([params valueForKey:@"access_token"] == nil)
[params setValue:self.accessToken forKey:@"access_token"];
}
这可以防止您指定为参数一部分的访问代码被 Facebook.accessToken 破坏。现在这会将图片发布到我感兴趣的页面。
但是,这是可行的,因为我是相关页面的管理员。其他用户将无法发布图片,图片将再次出现在他们自己的相册中,因为为该页面获取 access_token 的调用将返回 nil。
根据 Facebook 文档,如果页面不受限制,就像这个页面一样,那么应该可以向其张贴图片:
NOTE:
For connections that require an access token, you can use any valid access token if the page is public and not restricted. Connections on restricted pages require a user access token and are only visible to users who meet the restriction criteria (e.g. age) set on the page.
我是否提到我的页面是公开的且不受限制的?
Page Access Tokens
To perform the following operations as a Page, and not the current user, you must use the Page's access token, not the user access token commonly used for reading Graph API objects. This access token can be retrieved by issuing an HTTP GET to /USER_ID/accounts with the manage_pages permission. This will return a list of Pages (including application profilePages) to which the user has administrative access, along with access_tokens for those Pages. Alternatively, you can get a page access token for a single, specific, page by issuing an HTTP GET to /PAGE_ID?fields=access_token with themanage_pages permission, as described above. Publishing to a Page also requires the publish_stream permission, unless otherwise noted.
那么如何将图片发布到公共(public)/不受限制的页面?我可以从任何浏览器执行此操作,所以这是可能的,但如何使用 Graph API 完成?鉴于我可以在没有 access_token 恶作剧的情况下发布到 feed,发布图片有什么不同?
总而言之,我想做的是使用 Graph API 将图片(而不仅仅是缩略图 URL)发布到公共(public)/非受限页面。
最佳答案
我现在也是这个问题!我认为问题出在您重写的框架中的行,这变得不可能,因为 Facebook SDK 现在是无法编辑的静态库。但是,我已经想出了如何创建照片帖子而无需更改 SDK - 我使用从应用程序获取的 token 字符串创建新的 token 数据:
FBAccessTokenData *tokenData = [FBAccessTokenData createTokenFromString:tokenString permissions:[FBSession activeSession].accessTokenData.permissions expirationDate:[FBSession activeSession].accessTokenData.expirationDate loginType:FBSessionLoginTypeFacebookApplication refreshDate:nil];
然后我使用 fb appID(和 nullCacheInstance,不知何故它似乎很重要)创建新的 FBSession:
FBSession *sessionFb = [[FBSession alloc] initWithAppID:appID permissions:[NSArray arrayWithObjects: @"publish_stream", @"manage_pages", nil] urlSchemeSuffix:nil tokenCacheStrategy:[FBSessionTokenCachingStrategy nullCacheInstance]];
然后我打开新创建的 session 并创建了 tokenData,将这个新 session 设置为事件 session ,然后就可以了!
[sessionFb openFromAccessTokenData:tokenData completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
{
}];
[FBSession setActiveSession:sessionFb];
然后使用 Post 参数和源图像调用对 PageAppID/photos 的请求,它会将图像作为来自它自己的图像发布到 Facebook 页面墙上!
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos", PageAppID] parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];
我认为 activeSession 的改变类似于改变 Facebook.m 中的行
希望这对今天的人有帮助
关于iphone - 图片发布到 Facebook 最终出现在错误的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9374117/
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
我有一个rubyonrails应用程序。我按照facebook的说明添加了一个像素。但是,要跟踪转化,Facebook要求您将页面置于达到预期结果时出现的转化中。即,如果我想显示客户已注册,我会将您注册后转到的页面作为成功对象进行跟踪。我的问题是,当客户注册时,在我的应用程序中没有登陆页面。该应用程序将用户带回主页。它在主页上显示了一条消息,所以我想看看是否有一种方法可以跟踪来自Controller操作而不是实际页面的转化。我需要计数的Action没有页面,它们是ControllerAction。是否有任何人都知道的关于如何执行此操作的gem、文档或最佳实践?这是进入布局文件的像素
我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa
我是Rails的新手,所以请原谅简单的问题。我正在为一家公司创建一个网站。那家公司想在网站上展示它的客户。我想让客户自己管理这个。我正在为“客户”生成一个表格,我想要的三列是:公司名称、公司描述和Logo。对于名称,我使用的是name:string但不确定如何在脚本/生成脚手架终端命令中最好地创建描述列(因为我打算将其设置为文本区域)和图片。我怀疑描述(我想成为一个文本区域)应该仍然是描述:字符串,然后以实际形式进行调整。不确定如何处理图片字段。那么……说来话长:我在脚手架命令中输入什么来生成描述和图片列? 最佳答案 对于“文本”数