C# 使用WP-restapi请求C添加SEO#

C# 使用WP-restapi请求C添加SEO#,c#,wordpress,seo,C#,Wordpress,Seo,我正在使用WP restapi v2在Wordpress和All-In-One SEO Pack上发布SEO,但我不知道我应该给出哪些参数来添加元标题、元描述和元标记。我有以下代码: var request = (HttpWebRequest)WebRequest.Create(Website + "wp-json/wp/v2/posts/"); request.Headers["Authorization"] = "Bearer " + token; request.Method = "POS

我正在使用
WP restapi v2
在Wordpress和
All-In-One SEO Pack
上发布SEO,但我不知道我应该给出哪些参数来添加元标题、元描述和元标记。我有以下代码:

var request = (HttpWebRequest)WebRequest.Create(Website + "wp-json/wp/v2/posts/");
request.Headers["Authorization"] = "Bearer " + token;
request.Method = "POST";
request.UseDefaultCredentials = true;

var postData = "title=" + Title +
                   "&content=" + Content + // HTML Code
                   "&status=publish" +
                   "&date=" + TimeZone.CurrentTimeZone.ToUniversalTime(date).ToString("yyyy-MM-ddTHH:mm:ss");

var data = Encoding.ASCII.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;

using (var stream = request.GetRequestStream())
    stream.Write(data, 0, data.Length);

try
{
    var response = (HttpWebResponse)request.GetResponse();
    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
    var json = JObject.Parse("{" + JObject.Parse(responseString)["guid"].First + "}");
    LOG.Text = "Post posted at " + json["rendered"].ToString();
    list.Add(json["rendered"].ToString());
}
catch (Exception exception)
{
    MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}

WordPress是基于PHP构建的。因此WP-restapi插件也是用PHP编写的。 正如您提到的,您使用的是WordPressRESTAPIv2。 让我先分享代码的位置:

正如您所看到的,这个WP-restapi不包含任何SEO内容

现在您还安装了“一体式seo包”插件。不包括内置API。您可以升级到具有内置API的“一体式seo包”

或者,您可以通过添加其他端点来扩展自己的应用程序。然后自己编写PHP代码,通过RESTAPI管理SEO插件

这并不像Raunak Gupta告诉你的那样困难:这些是“多合一seo包”中使用的字段。使用其他端点扩展RESTAPI以配置它们。然后从C代码调用端点


_aioseop_标题
_aioseop_描述
_关键词
' . $标签;
die(“jQuery('div#aioseop_uu.'$target.'.'.$post_id.'')).fadeOut('fast',function(){var my_label=“.json_encode($output)。”;
jQuery('div#aioseop_u.'$target.'.'$post_id.'')).html(my_label).fadeIn('fast');
});" );
}
}

我看到您编写的代码与问题类似,但有人给出了任何解决方案。我不是一个C#人,但如果你在php方面需要任何帮助,我可以帮助你。而一体式SEO包使用以下post_meta保存元标记:
\u aioseop_title
用于元标题,
\u aioseop_description
用于元描述,
\u aioseop_关键字
用于元关键字。希望这对你有帮助。@RaunakGupta这很相似,因为这是我的问题(来自另一个帐户)。。。谢谢:)正如我看到的:他们要求57美元的年费来使用专业版。你只能在一个网站上使用它。如果你能详细告诉我你想要什么样的功能,我可能会为你构建它。也许更多的人需要这个功能,我可以向他们收取$$$。因为所有的SEO内容都存储在
post\u meta
字段中,它可以通过WP REST API进行修改,所以不需要专业版本的插件。若插件设置需要更改,它们会保存在wp_选项表中,这样也可以通过API进行更改(我猜)。
<wpml-config>
    <custom-fields>
        <custom-field action="translate">_aioseop_title</custom-field>
        <custom-field action="translate">_aioseop_description</custom-field>
        <custom-field action="translate">_aioseop_keywords</custom-field>
    </custom-fields>
    <admin-texts>
        <key name="aioseop_options">
            <key name="aiosp_home_title" />
            <key name="aiosp_home_description" />
            <key name="aiosp_home_keywords" />
            <key name="aiosp_post_title_format" />
            <key name="aiosp_page_title_format" />
            <key name="aiosp_category_title_format" />
            <key name="aiosp_archive_title_format" />
            <key name="aiosp_tag_title_format" />
            <key name="aiosp_search_title_format" />
            <key name="aiosp_description_format" />
            <key name="aiosp_404_title_format" />
            <key name="aiosp_paged_format" />
        </key>
    </admin-texts>    
</wpml-config>
if ( !function_exists( 'aioseop_ajax_save_meta' ) ) {
    function aioseop_ajax_save_meta() {
        if ( !empty( $_POST['_inline_edit'] ) && ( $_POST['_inline_edit'] != 'undefined' ) )
            check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
        $post_id = intval( $_POST['post_id'] );
        $new_meta = strip_tags( $_POST['new_meta'] );
        $target = $_POST['target_meta'];
        check_ajax_referer( 'aioseop_meta_' . $target . '_' . $post_id, '_nonce' );
        $result = '';
        if ( in_array( $target, Array( 'title', 'description', 'keywords' ) ) && current_user_can( 'edit_post', $post_id ) ) {
            update_post_meta( $post_id, '_aioseop_' . $target, esc_attr( $new_meta ) );
            $result = get_post_meta( $post_id, '_aioseop_' . $target, true );
        } else {
            die();
        }
        if( $result != '' ): 
            $label = "<label id='aioseop_label_{$target}_{$post_id}'><span style='width: 20px;display: inline-block;'></span>" . $result . '</label>';  
        else: 
            $label = "<label id='aioseop_label_{$target}_{$post_id}'></label><span style='width: 20px;display: inline-block;'></span><strong><i>" . __( 'No', 'all-in-one-seo-pack' ) . ' ' . $target . '</i></strong>';
        endif;
        $nonce = wp_create_nonce( "aioseop_meta_{$target}_{$post_id}" );
        $output = '<a id="' . $target . 'editlink' . $post_id . '" class="aioseop_edit_link" href="javascript:void(0);"'
            . 'onclick=\'aioseop_ajax_edit_meta_form(' . $post_id . ', "' . $target . '", "' . $nonce . '");return false;\' title="' . __('Edit') . '">'
            . '<img class="aioseop_edit_button" id="aioseop_edit_id" src="' . AIOSEOP_PLUGIN_IMAGES_URL . '/cog_edit.png" /></a> ' . $label;
        die( "jQuery('div#aioseop_" . $target . "_" . $post_id . "').fadeOut('fast', function() { var my_label = " . json_encode( $output ) . ";
              jQuery('div#aioseop_" . $target . "_" . $post_id . "').html(my_label).fadeIn('fast');
        });" );
    }
}