我想在应用程序的默认相册中为用户上传照片到Facebook.这是在这里发布的描述:http: //developers.facebook.com/docs/reference/api/photo
这里已经回答了这个方法:如何使用Facebook Graph API将照片上传到相册.我使用以下内容:
$args = array(
'message' => 'Photo Caption',
'image' => '@'.realpath("image.png")
);
$data = $facebook->api('/me/photos', 'post', $args);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试这个时,我得到了异常"(#324)需要上传文件".我有一个有效的会话,我有publish_stream和user_photos权限.我可以使用API检索数据.图像文件绝对有效,因为它可以加载file_get_contents(realpath("image.png")).
我尝试过这个解决方案,使用curl,效果很好: 使用Facebook的Graph API将照片上传到相册
$args = array(
'message' => 'Photo from application',
'pic.png' => '@'.realpath('pic.png')
);
$tok = $session['access_token']
$url = 'http://graph.facebook.com/'.$album_id.'/photos?access_token='.$tok;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)
与Facebook的PHP SDK curl相比,它看起来像这样(使用相同的$ args和$ url):
$ch = curl_init();
$opts = …Run Code Online (Sandbox Code Playgroud) 我有一个项目列表,每个项目都包含一个复选框.当勾选一个复选框时,我希望该项目将自己排序到列表的开头,最好是用鼠标拖动动画(但没有鼠标光标).
这可能吗?我在过去触发可拖动/可排序的事件时遇到了麻烦.我对替代解决方案持开放态度,只需明确项目移动到的位置即可.
编辑:我原本试图询问如何在jQuery sortable()列表中实现这一点,但我显然没有那么好地沟通,所以我更新了问题以匹配所有精彩的答案.
如果我有一个字典对象,例如:
const x = {
foo: {inner: 3},
bar: {inner: 'hi'},
};
Run Code Online (Sandbox Code Playgroud)
哪里有一个不同类型的内部属性(例如这里的字符串和数字)。
然后我想将其映射到一个如下所示的结构:
const y = {
foo: 3,
bar: 'hi',
};
Run Code Online (Sandbox Code Playgroud)
不过,我希望能够自动执行此操作,而不会丢失任何类型信息。这在打字稿中可能吗?
我几乎可以用 lodash 到达那里:
import { mapValues } from 'lodash';
const y: Y = mapValues(x, (z) => z.inner);
Run Code Online (Sandbox Code Playgroud)
然而,这最终会采用字典中所有类型的并集,并带有类型签名:
const y: {
foo: string | number;
bar: string | number;
}
Run Code Online (Sandbox Code Playgroud)
而不是想要的:
const y: {
foo: number;
bar: string;
};
Run Code Online (Sandbox Code Playgroud) 我有一个有before_update回调的模型.根据我的理解,在模型实例上before_update调用时update_attributes调用.我的假设是,如果before_update回调返回false记录将不会更新.
然而,这似乎不像假设的那样起作用.每次我打电话update_attributes,即使before_update返回,记录也会被保存false.您是否知道如何在before_update返回时阻止记录更新false?这是我在user.rb文件中尝试过的内容:
class User < ActiveRecord::Base
validates :first_name, :last_name, :presence => true
before_update do
false
end
end
Run Code Online (Sandbox Code Playgroud)
这是我在rails控制台中尝试的内容:
u = User.new(:first_name=>"John", :last_name => "Doe")
=> #<User id: nil, first_name: "John", last_name: "Doe", created_at: nil, updated_at: nil>
u.update_attributes(:first_name=>nil)
=> false
u.changed?
=> true
u
=> #<User id: nil, first_name: nil, last_name: "Doe", created_at: nil, updated_at: nil>
Run Code Online (Sandbox Code Playgroud) activerecord ×1
animation ×1
facebook ×1
jquery ×1
photo-upload ×1
php ×1
ruby ×1
typescript ×1